Passthru () + pipe in subprocess= Traceback (ultima chiamata più recente): (...) in stdout= subprocess.pipe)

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

Domanda

Ho un errore quando sto usando passthru () per chiamare uno script Python (usando sottopressione e tubo) con PHP.

Ecco l'errore:

.

Traceback (la più recente chiamata ultima): file "... / desktop / h.py", linea 11, in stdout= subprocess.pipe) #Set up il comando convert e dirigere l'output in un file di tubi "/ Sistema /Biblioteca / Frameworks / Python.Framework / Versioni / 2,5 / lib / python2.5 / subprocess.py ", linea 593, in init erread, errwrite) File" / System / Library / Frameworks / Python.Framework / Versions / 2.5 / lib / python2.5 / subprocess.py ", linea 1079, in _execute_child Solleva Child_Exception Oserror: [ERRNO 2] Nessun file o directory

Il PHP Passthru:

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

La mia linea Python che causa l'errore:

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

Come usare stdout= subprocess.pipe correttamente nella sottoprocesso?

Attenersi alle tue risposte.

È stato utile?

Soluzione

Sembra che il tuo percorso non abbia la directory incluso il comando "Convert".Prova a sostituire:

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

Con:

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

Dove "/ pieno / percorso / a / converti" potrebbe essere qualcosa come "/ usr / bin / convert".

Altri suggerimenti

È perché deve essere eseguito tramite una shell, quindi è necessario impostare il punto di shell su true:

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top