muchas gracias Anler me sirvio de mucho tu ejemplo...
saludos
----- Mensaje original -----
De: "Anler Hernández Peral" <anle...@gmail.com>
Para: "La lista de python en castellano" <python-es@python.org>
Enviados: Martes, 10 de Mayo 2011 18:41:50 (GMT-0500) Auto-Detected
Asunto: Re: [Python-es] subprocess
Hola Yixander, intenta con lo siguiente:
#######################################
"""
Emulates
ps aux | grep sbin | sort -k 9
ref: http://docs.python.org/library/subprocess.html#replacing-shell-pipeline
"""
import subprocess
ps = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
grep = subprocess.Popen(['grep', 'sbin'], stdin=ps.stdout,
stdout=subprocess.PIPE)
ps.stdout.close()
sort = subprocess.Popen(['sort', '-k', '9'], stdin=grep.stdout,
stdout=subprocess.PIPE)
grep.stdout.close()
output = sort.communicate()[0]
print output
##########################################
2011/5/7 Yixander de la Paz Milán < ydmi...@estudiantes.uci.cu >
buenas noches:
estoy desarrollando un proyecto donde trabajo con la libreria subprocess, y
quisiera ejecutar el siguiente comando y luego trabajar con el resultado del
mismo
tengo esto:
ruta = subprocess.Popen("hostname", stdout=subprocess.PIPE)
resultado = ruta.communicate()[0]
se que el resultado de salida lo almacena en result, pero como ejecutar un
comando que contenga el caracter "|" por ejemplo este --> "ps auxww | grep
postgres: | sort -k 9", se que incluso puedo hacer esto:
ruta = subprocess.Popen("ls", "-l", stdout=subprocess.PIPE)
resultado = ruta.communicate()[0]
pero como decía anteriormente quisiera ejecutar este comando "ps auxww | grep
postgres: | sort -k 9" como lo hago con "hostname" y "ls" "-l" ...
Saludos
_______________________________________________
Python-es mailing list
Python-es@python.org
http://mail.python.org/mailman/listinfo/python-es
FAQ: http://python-es-faq.wikidot.com/
_______________________________________________ Python-es mailing list
Python-es@python.org http://mail.python.org/mailman/listinfo/python-es FAQ:
http://python-es-faq.wikidot.com/
_______________________________________________
Python-es mailing list
Python-es@python.org
http://mail.python.org/mailman/listinfo/python-es
FAQ: http://python-es-faq.wikidot.com/