No idea why you would want to do that (looks more complicated in python
than in bash, right?)... but:
f = open("log.txt", "w")
f.write(output)
f.close()
--
*Braga, Bruno*
www.brunobraga.net
[email protected]
On Wed, May 9, 2012 at 12:18 AM, Rogelio <[email protected]> wrote:
> 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'
> _______________________________________________
> Tutor maillist - [email protected]
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor