Get the complete command line as-is

Thomas Heller theller at ctypes.org
Thu Sep 13 05:19:11 EDT 2007


wangzq schrieb:
> On Sep 12, 3:20 pm, Laurent Pointal <laurent.poin... at limsi.fr> wrote:
>> wangzq a écrit :
>>
>> > Hello,
>>
>> > I'm passing command line parameters to my browser, I need to pass the
>> > complete command line as-is, for example:
>>
>> > test.py "abc def" xyz
>>
>> > If I use ' '.join(sys.argv[1:]), then the double quotes around "abc
>> > def" is gone, but I need to pass the complete command line ("abc def"
>> > xyz) to the browser, how can I do this?
>>
>> > I'm on Windows.
>>
>> As Windows command-line parsing seem to remove some chars, maybe you can
>> try to use the GetCommandLine() function from Win32 API (I dont know if
>> it is available in pywin32 package - you may need to write a wrapper
>> with ctypes).
>>
>> Seehttp://msdn2.microsoft.com/en-us/library/ms683156.aspx
>>
>> A+
>>
>> Laurent.
> 
> Thank you for the tip. It works:
> 
> import ctypes
> 
> p = ctypes.windll.kernel32.GetCommandLineA()
> print ctypes.c_char_p(p).value
> 

Better would be this code:

import ctypes
ctypes.windll.kernel32.GetCommandLineA.restype = ctypes.c_char_p
print ctypes.windll.kernel32.GetCommandLineA()

Thomas




More information about the Python-list mailing list