2013-11-02 152 views
0

我遇到了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 
+0

這是爲什麼downvoted? – c12

+2

請發佈完整的回溯。 –

+2

您沒有找到_executable_而不是一個進程。 –

回答

0

嘗試從控制檯運行它。確保權限/可執行性是正確的。試試os.system()。

相關問題