2016-02-24 39 views
1

我想從python本身運行子進程的praat文件,但python(子進程)似乎無法找到目錄。我不明白爲什麼當我在終端中運行命令時,它工作得很好。任何人都不能指導我去哪裏錯了? 這是子碼python中的子進程錯誤

import silex 
import subprocess as sb 
cmd_line = raw_input() 
args = shlex.split(cmd_line) 
p = sb.Popen(args) 

當我輸入運行

Praat /Users/admirmonteiro/tmp/tmp.praat 

這是我的錯誤:

Traceback (most recent call last): 
    File "<input>", line 1, in <module> 
    File "/Users/admirmonteiro/anaconda/lib/python2.7/subprocess.py", line 710, in __init__ 
    errread, errwrite) 
    File "/Users/admirmonteiro/anaconda/lib/python2.7/subprocess.py", line 1335, in _execute_child 
    raise child_exception 
OSError: [Errno 2] No such file or directory 

如前所述,我運行的命令和他們在終端上運行良好。 我也想跑subprocess.call但發生同樣的錯誤。我也嘗試過使用shell = True作爲參數,但也輸出相同的錯誤。 請幫忙!

+0

手動運行時哪個'Praat'返回什麼? –

+0

如果我自己輸入它,它會打開應用程序。如果我像上面提到的那樣用文件打開它,它會運行返回另一個文件的文件。如果我在終端上這樣做,它會起作用。 – Aboogie

+0

另外,當我運行subprocess.call([Praat「])時,我得到了錯誤:call([」Praat「],shell = True) /bin/sh:Praat:command not found 127這是沒有意義的,當我在終端運行Praat時,它工作正常,我很困惑 – Aboogie

回答

1

在shell中鍵入以下內容以獲取Praat應用程序的完整路徑。

whereis Praat 

然後在你的python程序中使用完整路徑。

+1

注:''鍵入Praat'('whence','where','which')或'命令-v Praat'可能更爲有用這裏,找到完整的可執行文件路徑。參見[什麼是unix命令找出可執行文件cor響應一個給定的命令(http://superuser.com/q/351889/13868) – jfs

+1

相關:[爲什麼不使用「哪個?」用什麼呢?(http://unix.stackexchange.com/q/85249/1321) – jfs

+0

根據手冊頁,'whereis'檢查標準二進制目錄(...)打印出的任何發現的路徑,'which'將在用戶的路徑中找到一個程序。所以'哪個'可能是更好的選擇,因爲OP說他能夠在命令行中運行它。 –