Re: os中的execl, execle, exec lp等函数用来执行系统命令,为 什么会replace current process呢?

yrh <[email protected]> Tue, 22 Jan 2008 21:53:13 +0800
Newsgroups gmane.comp.python.chinese
Message-ID <[email protected]>
在cmd里有空格时用多重引号,如:
os.system('""c:\document and settings\usera\a.exe" "-a "-b" "-c""')
注意两头有3个引号,一个单引号,两个双引号

单引号是python的需要,表示字符串,两个双引号是cmd的需要

在cmd里,os.system(r"c:\document and settings\usera\a.exe -a -b
-c")这个肯定不行,因为cmd无法处理其中的空格。
这个问题也曾困扰我很久,我记得好像是在微软的网站上找到的答案。


在08-1-22,Joey <[email protected]> 写道:
>
> Hi All,
>
> 想用Python来调用系统命令,遇到了问题。
> 例如想调用a.exe,并跟一些参数,命令格式为: a.exe -a -b -c
> 由于用户当前工作目录不确定,于是决定考虑使用绝对路径
> c:\a.exe -a -b -c
> 由于a.exe的路径不确定,有可能存在
> c:\document and settings\usera\a.exe -a -b -c的情况,空格导致命令无法正常执行。
> 用os.system("c:\document and settings\usera\a.exe -a -b -c")就会出现错误。
> 我使用 "c:\document and settings\usera\a.exe" -a -b -c 在command line里面是正常执行的,
> 但是使用os.system()的话,提示错误。不知道为什么。
>
> 于是决定考虑使用os中的execv函数来执行这个命令,但是发现所有的exec*函数都提到会replace current process。
>
> 有没有函数能达到execv的效果,但是不replace current process呢?
>
> 十分感谢。
>
> --
> Best Regard,
> Tang, Jiyu (Joey)
>
> _______________________________________________
> python-chinese
> Post: send [email protected]
> Subscribe: send subscribe to [email protected]
> Unsubscribe: send unsubscribe to  [email protected]
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>

_______________________________________________
python-chinese
Post: send [email protected]
Subscribe: send subscribe to [email protected]
Unsubscribe: send unsubscribe to  [email protected]
Detail Info: http://python.cn/mailman/listinfo/python-chinese