Search code examples
subprocesspipetracebackpassthru

passthru() + Pipe in subprocess = Traceback (most recent call last): (…) in stdout=subprocess.PIPE)


I've got an error when I'm using passthru() to call a python script (using subprocess and pipe) with PHP.

Here is the error:

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 

The PHP passthru:

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

My Python line which cause the error:

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

How to use stdout=subprocess.PIPE properly in the subprocess?

Looking forward your answers.


Solution

  • It looks like your PATH doesn't have the directory including the "convert" command. Try replacing:

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

    with:

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

    where "/full/path/to/convert" might be something like "/usr/bin/convert".