我遇到了Python在我的Linux機器上查找可用可執行文件的問題。我的默認路徑包括這個可執行文件(svnlook),但是當我運行python腳本時,下面的函數無法找到可執行文件。有想法該怎麼解決這個嗎?Python subprocess.Popen找不到可執行文件
def command_output(cmd):
child = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
output = child.communicate()[0]
return output, child.returncode
def get_author():
cmd = "svnlook author %s %s %s" % (svn_opt, svn_txn, svn_repo)
author, return_code = command_output(cmd)
return author.strip()
錯誤:
Traceback (most recent call last):
File "/home/user/app/csvn/data/repositories/repo/hooks/pre-commit", line 82, in <module>
author = get_author()
File "/home/user/app/csvn/data/repositories/repo/hooks/pre-commit", line 53, in get_author
author, return_code = command_output(cmd)
File "/home/user/app/csvn/data/repositories/repo/hooks/pre-commit", line 36, in command_output
child = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
File "/home/user/app/activepython-2.7.2.5_x86_64/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/home/user/app/activepython-2.7.2.5_x86_64/lib/python2.7/subprocess.py", line 1228, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Error: [Errno 2] No such file or directory
這是爲什麼downvoted? – c12
請發佈完整的回溯。 –
您沒有找到_executable_而不是一個進程。 –