2012-03-14 51 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 
相关问题