我想從python運行gphoto2,但沒有成功。它只是返回命令未找到。 gphoto正確安裝,因爲在終端中的命令工作正常。Python子進程調用返回「命令未找到」,終端正確執行
p = subprocess.Popen(['gphoto2'], shell=True, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, executable='/bin/bash')
for line in p.stdout.readlines():
print line
p.wait()
/bin/bash: gphoto2: command not found
我知道有一些有趣的關於OSX終端(應用程序),但是,我對OSX的知識是微薄的。
對此有何看法?
編輯
改變了我的一些代碼,其他的錯誤使用完整路徑 '的/ opt/local/bin目錄/ gphoto2'
但如果出現
p = subprocess.Popen(['gphoto2'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in p.stdout:
print line
raise child_exception
OSError: [Errno 2] No such file or directory
編輯
人小心解釋使用哪個shell或如何登錄並能夠具有相同的功能..?
你爲什麼不使用'subprocess.check_output() '或者一次輸出整個東西? – Gandaro 2012-02-29 21:00:05