我遇到Python在我的Linux机器上找到可用的可执行文件的问题。我的默认PATH包含这个可执行文件(svnlook)但是当我运行python脚本时,下面的函数无法找到可执行文件。关于如何解决这个问题的任何想法?
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
答案 0 :(得分:1)
您可能希望提供可执行文件的完整路径,例如/usr/bin/svnlook
或/usr/local/bin/svnlook
而非svnlook
。
有关详细信息,请参阅this answer to a related question。
答案 1 :(得分:0)
尝试从控制台运行它。确保权限/可执行性正确。尝试os.system()。