473,503 Members | 1,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get the complete command line as-is

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.

Thanks.

Sep 12 '07 #1
11 7471
wangzq wrote:
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.

Thanks.
You can't. The quotes are gobbled by the command-line processor before
your program ever gets the chance to see them. You could try writing
your own command shell ... or learn how to quote the quotes.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

Sep 12 '07 #2
On Sep 11, 8:00 pm, wangzq <wan...@gmail.comwrote:
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.

Thanks.
I'm on Solaris and this works for me:

test.py '"abc def" xyz'

print sys.arv[1]

"abc def" xyz

Sep 12 '07 #3
On Sep 11, 8:33 pm, TheFlyingDutchman <zzbba...@aol.comwrote:
On Sep 11, 8:00 pm, wangzq <wan...@gmail.comwrote:
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.
Thanks.

I'm on Solaris and this works for me:

test.py '"abc def" xyz'

print sys.arv[1]

"abc def" xyz
OK, now I'm on Windows XP and things aren't looking too good.

It seems that \" will retain the quote marks but then the spaces get
gobbled.

But if you replace the spaces with another character:

python.exe test.py \"abc#def\"#123

then:

import sys
commandLine = "".join(sys.argv[1:])

prints commandLine.replace('#',' ')

gives:

"abc def" 123

Don't know if you can use that technique or not.

Sep 12 '07 #4
>
It seems that \" will retain the quote marks but then the spaces get
gobbled.

But if you replace the spaces with another character:

python.exe test.py \"abc#def\"#123

then:

import sys
commandLine = "".join(sys.argv[1:])

prints commandLine.replace('#',' ')

gives:

"abc def" 123

Don't know if you can use that technique or not.
Came back for a second try and found out that:

python.exe test.py "\"abc def\" 123"

import sys
commandLine = "".join(sys.argv[1:])

print commandLine

gives:

"abc def" 123

Sep 12 '07 #5
>
python.exe test.py "\"abc def\" 123"

import sys
commandLine = "".join(sys.argv[1:])

print commandLine

gives:

"abc def" 123
With the surrounding quotes you actually only need:

commandLine = sys.argv[1]

Sep 12 '07 #6
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).

See http://msdn2.microsoft.com/en-us/library/ms683156.aspx
A+

Laurent.
Sep 12 '07 #7
wangzq wrote:
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.

Thanks.
Question: If you don't want to parse this as a command line, why don't you read
it as data via raw input or from some configuration file?

something like:

python program (pgm.py):

cmdline=raw_input("enter your parameters")
external file (cmd.txt):

"abc def" xyz

python pgm.py < cmd.txt

-Larry
Sep 12 '07 #8
On Sep 12, 3:20 pm, Laurent Pointal <laurent.poin...@limsi.frwrote:
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

Now I only need to split the whole command line into 3 parts and get
the last one.

Thanks for all your input.
Sep 13 '07 #9
wangzq wrote:
On Sep 12, 3:20 pm, Laurent Pointal <laurent.poin...@limsi.frwrote:
>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

Now I only need to split the whole command line into 3 parts and get
the last one.
Well, FWIW, it is exposed by pywin32:

<code>
import win32api
print win32api.GetCommandLine ()

</code>

TJG
Sep 13 '07 #10
wangzq schrieb:
On Sep 12, 3:20 pm, Laurent Pointal <laurent.poin...@limsi.frwrote:
>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

Sep 13 '07 #11
Thomas Heller wrote:
Better would be this code:

import ctypes
ctypes.windll.kernel32.GetCommandLineA.restype = ctypes.c_char_p
print ctypes.windll.kernel32.GetCommandLineA()
Or you could use pywin32:

<code>
import win32api

print win32api.GetCommandLine ()

</code>

TJG
Sep 13 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2019
by: Tony C | last post by:
According to the help for pydoc, it can be run as a script, from the command line. "Or, at the shell command line outside of Python: Run "pydoc <name>" to show documentation on something" ...
7
6018
by: Ken Innes | last post by:
I am trying to write a little program that can be run as a Windows program or as a command line program. I'm really not sure the best way to do this, so what I came up with so far was to check for...
6
1805
by: leegold2 | last post by:
I have Apachce Mysql PHP on my PC (localhost) at home. I have a small db with a table or "two". I want to set up AMP on my PC at work and I want to import my home db to my work PC (both win32). ...
6
2589
by: Hari | last post by:
can i have command line arguments in VS.NET applicatio? if yes how? Can i have some code snippets of the above functionality? I know we can acjieve this in console application form command...
25
3287
by: David Bernier | last post by:
I'd like to pass on the command line two filenames. As for example: my_executable filename_1 filename_2 I haven't done any C programming with command line arguments so far. I'm familiar...
1
3373
by: Manish | last post by:
I have the following code in a script -------------------------------------------------------------------------------------------------------------------------------- foreach($serverlist as...
16
2682
by: John Salerno | last post by:
Here's my new project: I want to write a little script that I can type at the terminal like this: $ scriptname package1 where scriptname is my module name and any subsequent arguments are the...
2
2741
by: Milan | last post by:
Hi, Please guide me how to set command line argument and how to retrive command line argument. Senario: vb.net application should be able to execute from command prompt by passing login and...
0
1265
by: Tharpa Roberts | last post by:
Under Visual C++ 6.0, if you made a command-line program, it would stay open after execution, and then you would press any key to close it. Under Visual Studio 2005, if you make a C++ command...
0
2256
by: Liam Se Imihaf | last post by:
Hi all, I have a problem get the "command line" of a process in C# for some processes (ie, tomcat5.exe). I am using Win2003. I can use wmci as in: wmic process where name="tomcat5.exe" get...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7084
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7278
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.