J'ai essayé d'exécuter ce code à partir du livre 'Python Standard Library' de 'Fred Lunde'.remplacement de sous-processus de popen2 avec Python
import popen2, string
fin, fout = popen2.popen2("sort")
fout.write("foo\n")
fout.write("bar\n")
fout.close()
print fin.readline(),
print fin.readline(),
fin.close()
Il fonctionne bien avec un avertissement de
~/python_standard_library_oreilly_lunde/scripts/popen2-example-1.py:1: DeprecationWarning: The popen2 module is deprecated. Use the subprocess module.
Comment traduire la fonction précédente avec sous-processus? J'ai essayé comme suit, mais ça ne marche pas.
from subprocess import *
p = Popen("sort", shell=True, stdin=PIPE, stdout=PIPE, close_fds=True)
p.stdin("foo\n") #p.stdin("bar\n")
* quelques erreurs *? – SilentGhost