gpt4 book ai didi

python - 使用 check_call 调用 shell 脚本

转载 作者:太空宇宙 更新时间:2023-11-03 19:07:52 25 4
gpt4 key购买 nike

我在调用 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

最佳答案

添加 shell=True 修复它

check_call(['./test.sh'],shell=True)

关于python - 使用 check_call 调用 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14118024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com