Passthru()+ subprocess的管道= tackback(最近呼叫最后):(...)在stdout= subprocess.pipe)

StackOverflow https://stackoverflow.com//questions/9707520

当我使用passthru()来调用python脚本(使用子进程和管道)时出现错误。

这是错误:

返回(最近呼叫最后一个):文件“... /桌面/ h.py”,第11行,在stdout= subprocess.pipe中)#向上转换命令并将输出引导到管道文件“/系统/库/框架/ python.framework /版本/ 2.5 / lib / python2.5 / subprocess.py“,第593行, init errread,errwrite)文件”/ system / library / frameworks / python。框架/版本/ 2.5 / lib / python2.5 / subprocess.py“,第1079行,在_execute_child中引发shild_exception oserror:[errno 2]没有这样的文件或目录

php passthru:

<?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
.

如何在子过程中正确使用stdout= subprocess.pipe?

期待您的答案。

有帮助吗?

解决方案

看起来您的路径没有包含“转换”命令的目录。尝试替换:

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

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

其中“/ full / path / to / convert”可能是“/ usr / bin / convert”。

其他提示

是因为它需要通过shell执行,因此您需要将shell参数设置为true:

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top