[Fwd: Re: [Tutor] What am I missing?]

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Mon Sep 27 09:04:09 CEST 2004



On Sun, 26 Sep 2004, Danny Yoo wrote:

>
>
> On Mon, 27 Sep 2004, Tom Tucker wrote:
>
> > I think I found the issue.  My "for" and "if" statements were never
> > reached.  The system call "logfile = os.system('tail -f
> > /var/log/messages')" doesn't appears to be communicating outside of
> > itself.  It was just printing to STDOUT.  Back to the drawing board!
>
>
> Ah!  Use os.popen(), not os.system().  The problem is that os.system()
> waits until the command is finished.  But 'tail -f' never terminates.
> *grin*

Hi Tom,

I should clarify that os.popen() and os.system() are used for different
purposes.

Their main difference is return type value.  Both of them start up
external processes.  But os.popen() gives us back an open file object.
os.system() waits until the external commands finishes, and then returns
the "errorlevel" status code.

So os.system() is definitely not what you want, since you want to do some
post-processing on the STDOUT of the program.


The blocking stuff that I mentioned in the previous mail is one additional
complication.  Usually people don't have to worry about blocking issues at
all.  But it applies to your situation because you're dealing with an
external process ("tail -f") that just won't terminate.  In that case, we
have to do a bit extra to make things work right.

Hope this clears things up!



More information about the Tutor mailing list