按原样获取完整的命令行 [英] Get the complete command line as-is

查看:75
本文介绍了按原样获取完整的命令行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我正在将命令行参数传递给我的浏览器,我需要按原样传递

完整命令行,例如:


test.py" abc def" xyz


如果我使用''''。join(sys.argv [1:]),那么双引号abc

def已经不见了,但我需要将完整的命令行(abc def

xyz)传递给浏览器,我该怎么办呢?


我在Windows上。


谢谢。

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.

推荐答案

wangzq写道:
wangzq wrote:

您好,


我将命令行参数传递给我的浏览器,我需要通过

完整的命令行,例如:


test.py" abc def" xyz


如果我使用''''。join(sys.argv [1:]),那么双引号abc

def已经不见了,但我需要将完整的命令行(abc def

xyz)传递给浏览器,我该怎么办呢?


我在Windows上。


谢谢。
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.



你不能。在你的程序有机会看到它们之前,命令行处理器会引用引号。您可以尝试编写

您自己的命令shell ...或者学习如何引用引号。


问候

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 ------------------

上网:博客,镜头和标签互联网

许多服务目前提供免费注册

-----------感谢您阅读------------ -

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 -------------


9月11日晚上8点,wangzq< wan ... @ gmail.comwrote:
On Sep 11, 8:00 pm, wangzq <wan...@gmail.comwrote:

您好,


我正在将命令行参数传递给我的浏览器,我需要通过

完成命令按原样排列,例如:


test.py" abc def" xyz


如果我使用''''。join(sys.argv [1:]),那么双引号abc

def已经不见了,但我需要将完整的命令行(abc def

xyz)传递给浏览器,我该怎么办呢?


我在Windows上。


谢谢。
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.



我在Solaris上这对我有用:


test.py''" abc def" xyz''


print sys.arv [1]


" abc def" xyz

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

test.py ''"abc def" xyz''

print sys.arv[1]

"abc def" xyz


9月11日晚上8:33,TheFlyingDutchman< zzbba ... @ aol.comwrote:
On Sep 11, 8:33 pm, TheFlyingDutchman <zzbba...@aol.comwrote:

9月11日晚上8点,wangzq< wan ... @ gmail.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
test.py "abc def" xyz


如果我使用''''。join(sys.argv [1:]),那么双引号就是abc

def"已经不见了,但我需要将完整的命令行(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?


我在Windows上。
I''m on Windows.


谢谢。
Thanks.



我在Solaris上这对我有用:


test.py''" abc def" xyz''


print sys.arv [1]


" abc def" xyz


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

test.py ''"abc def" xyz''

print sys.arv[1]

"abc def" xyz



好​​的,现在我在Windows XP上,看起来不太好。


它似乎是\将保留引号,但随后空格获得

gobbled。


但如果你用其他字符替换空格:


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

然后:


import sys

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


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


给出:


" abc def" 123


不知道你是否可以使用这种技术。

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.


这篇关于按原样获取完整的命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆