【问题标题】:Calling shell script using check_call使用 check_call 调用 shell 脚本
【发布时间】:2013-01-02 06:54:48
【问题描述】:

我在调用 shell 脚本时遇到以下错误,如何使用 check_call 或通过任何其他 python 函数调用 shellscript?
导入操作系统 from subprocess import 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

【问题讨论】:

    标签: python


    【解决方案1】:

    添加 shell=True 修复了它

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

    【讨论】:

      猜你喜欢
      • 2015-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-22
      • 2014-06-05
      相关资源
      最近更新 更多