【发布时间】:2014-01-06 10:11:48
【问题描述】:
我需要使用 python 执行一个 shell 脚本。 shell 程序的输出是一个文本文件。脚本没有输入。帮我解决这个问题。
def invokescript( shfile ):
s=subprocess.Popen(["./Script1.sh"],stderr=subprocess.PIPE,stdin=subprocess.PIPE);
return;
invokescript("Script1.sh");
在使用上述代码时,我收到以下错误。
Traceback (most recent call last):
File "./test4.py", line 12, in <module>
invokescript("Script1.sh");
File "./test4.py", line 8, in invokescript
s=subprocess.Popen(["./Script1.sh"],stderr=subprocess.PIPE,stdin=subprocess.PIPE);
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 8] Exec format error
提前谢谢...
【问题讨论】:
-
python中不需要分号
-
ITYM
s = subprocess.Popen([shfile], ...)。否则你就不需要那个参数了。 -
顺便说一句,如果调用者需要它,你应该返回这个
s。