[Tutor] opening a pipe?
Thomas Pani
thomas.pani at gmail.com
Tue Feb 12 15:03:42 CET 2008
The subprocess module is what you're looking for.
Your example would look like
--------------------%<--------------------
import subprocess
p = subprocess.Popen('cat hi.txt', shell=True, stdout=subprocess.PIPE)
for line in p.stdout:
print line
--------------------%<--------------------
I assume you know that you can just open a file for reading instead of
piping cat.
thomas
James Hartley wrote:
> A Perl script can easily serve as a filter within a pipe as seen in
> the following:
>
> use strict;
> use warnings;
>
> open(IN, 'cat hello.txt |') or die 'unable to open file';
> while (<IN>) {
> print;
> }
> close(IN);
>
> Can I do the same within Python? Thanks.
>
> Jim
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list