Re: os中的execl, execle, execlp 等函数用来执行系统命令,为什么会replace curre nt process呢?
"kilnt.huo" <[email protected]> Tue, 22 Jan 2008 12:49:18 +0800
| Newsgroups | gmane.comp.python.chinese |
|---|---|
| Message-ID | <[email protected]> |
os.popen
def cmn_exec_cmd_and_get_list( cmd, split_symbol = '\n' ):
""" execute a external command and split output into list, then return
the list
"""
out = os.popen( cmd, 'r')
out_txt = out.read()
ret = out.close()
if ret:
raise RuntimeError, '%s failed with exit code %d' % (cmd, ret)
list = out_txt.split( split_symbol )
return list
windows 下的路径有时候有 8.3 的历史遗留问题,换成 ~1 这样就好了。
> 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