execute shell command pipeline

Paul Paul.Sue at telus.com
Thu Mar 25 15:15:28 EST 2004


Hi,

I'm a Python newbie and I'm wondering how I can do the following Perl thing:

open(F, 'grep -b 2004 logfile | head -1 | cut -d: -f1 |') or die "blah, blah";
$offset = <F>;
( or $offset = `grep -b 2004 logfile | head -1 | cut -d: -f1`; )

in Python.  When I tried:

offset = os.popen('grep -b 2004 logfile | head -1 |cut -d: -f1').read()

I get a whole bunch of error messages --

grep: writing output: Broken pipe

Any help would be most appreciated.

Regards,

Paul



More information about the Python-list mailing list