1

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.

glglgl
  • 89,107
  • 13
  • 149
  • 217
Zorkzyd
  • 929
  • 3
  • 12
  • 30

2 Answers2

1

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

amcnabb
  • 2,161
  • 1
  • 16
  • 24
0

It's because it needs to be executed through a shell, so you need to set shell argument to True:

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