execute shell command pipeline

Cameron Laird claird at lairds.com
Thu Mar 25 21:39:09 CET 2004


In article <8757b529.0403251215.29333930 at posting.google.com>,
Paul <Paul.Sue at telus.com> wrote:
>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
			.
			.
			.
Python has too many answers to this.  I recommend you start with
  import commands
  offset = commands.getoutput('grep -b 2004 logfile | head -1 |cut -d: -f1')

-- 

Cameron Laird <claird at phaseit.net>
Business:  http://www.Phaseit.net



More information about the Python-list mailing list