2012-03-14 47 views
0

我有一個錯誤,當我使用passthru()調用python腳本子進程和管道)與PHP。passthru()+管子進程=回溯(最近一次調用最後一次):(...)在stdout = subprocess.PIPE)

以下是錯誤:

Traceback (most recent call last): File "…/Desktop/h.py", line 11, in stdout=subprocess.PIPE) #set up the convert command and direct the output to a pipe File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/subprocess.py", line 593, in init errread, errwrite) File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/subprocess.py", line 1079, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory

的PHP中繼:

<?php 
passthru("/usr/bin/python2.5 /Users/Nagar/Desktop/h.py $argument1 $argument2 1 2>&1"); 
?> 

我的Python線,導致該錯誤:

p1 = subprocess.Popen(['convert', fileIn, 'pnm:-'], stdout=subprocess.PIPE) #set up the convert command and direct the output to a pipe 

如何使用標準輸出= subprocess.PIPE在子流程中正確嗎?

期待您的回答。

回答

0

看起來您的PATH沒有包含「convert」命令的目錄。嘗試更換:

p1 = subprocess.Popen(['convert', fileIn, 'pnm:-'], stdout=subprocess.PIPE) 

有:

p1 = subprocess.Popen(['/full/path/to/convert', fileIn, 'pnm:-'], stdout=subprocess.PIPE) 

其中 「/全/路徑/到/轉換」 可能是這樣的 「的/ usr/bin中/轉換」。

1

這是因爲它需要通過shell執行,所以你需要設置shell參數爲True:

p1 = subprocess.Popen(['convert', fileIn, 'pnm:-'], stdout=subprocess.PIPE, shell=True)convert command and direct the output to a pipe 
相關問題