import subprocess
retcode = subprocess.call(["/home/myuser/go.sh", "abc.txt", "xyz.txt"])
当我运行这两行时,我会这样做吗?:
/home/myuser/go.sh abc.txt xyz.txt
为什么会出现此错误?但是当我正常运行 go.sh 时,我没有收到该错误。
File "/usr/lib/python2.6/subprocess.py", line 480, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.6/subprocess.py", line 633, in __init__
errread, errwrite)
File "/usr/lib/python2.6/subprocess.py", line 1139, in _execute_child
raise child_exception
OSError: [Errno 8] Exec format error
最佳答案
OSError: [Errno 8] Exec format error
这是操作系统在尝试运行 /home/myuser/go.sh
时报告的错误。
在我看来,go.sh
的 shebang (#!
) 行无效。
这是一个从 shell 而非 Popen
运行的示例脚本:
#\!/bin/sh
echo "You've just called $0 $@."
从第一行删除 \
可以解决问题。
关于python - 这是在 Python 中运行 shell 脚本的正确方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4834483/