[Tutor] execute an OS command, get the output

Terry Carroll carroll at tjc.com
Sat Mar 11 17:51:13 CET 2006

On Sat, 11 Mar 2006, Alan Gauld wrote:

> Take a look at the OS topic in my tutorial. The process control section
> covers all of these calls and explains their differences. It also points out
> that the latter is intended to replace all the others and shows examples.

Excellent; I'll check it out.  Your tutorials have been vey helpful to me 
in the past.

> output = popen(command).read()
> isn't too hard is it?

That's exactly the sort of thing I'm thinking of.

> >  string xxxxxxx | grep zzzzzz | head -10
> But in this case I'd use Pytthon to search for the string and get the
> last 10 entries rather than grep/head...

That was my initial thought, but the files are 1-3 gigabytes.  The string 
command takes 10-15  minutes to get through a file.  I've been using the 
pipe sequence manually, so I know it works, and only takes a second or two 
to run.

The Python program is for my own use, so I don't have to worry about 
whether and where string/grep/head are installed.

More information about the Tutor mailing list