我在调用shell脚本时遇到以下错误,如何使用check_call或任何其他python函数调用shellscript?
进口口
来自子流程导入check_call,Popen,PIPE
def main ():
BUILD_ROOT="//local/mnt/workspace//AU"
os.chdir(BUILD_ROOT)
print os.getcwd()
check_call(['./test.sh'])
if __name__ == '__main__':
main()
错误: -
File "test.py", line 11, in <module>
main()
File "test.py", line 8, in main
check_call(['./test.sh'])
File "/usr/lib/python2.6/subprocess.py", line 493, in check_call
retcode = call(*popenargs, **kwargs)
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
答案 0 :(得分:1)
添加shell = True修复它
check_call(['./test.sh'],shell=True)