[Tutor] using subprocess to export files in bash

Rogelio scubacuda at gmail.com
Tue May 8 16:18:33 CEST 2012


While reading the subprocess documentation, I found a great example on
how to call commands with a PIPE

http://docs.python.org/library/subprocess.html

**************************
output=`dmesg | grep hda`
# becomes
p1 = Popen(["dmesg"], stdout=PIPE)
p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE)
p1.stdout.close()  # Allow p1 to receive a SIGPIPE if p2 exits.
output = p2.communicate()[0]

****************************

How do I do this and output to a file?

e.g.

output = "dmesg | grep hda > log.txt'


More information about the Tutor mailing list