does os.popen() search the path?
schorsch at schorsch.com
Mon Oct 16 15:29:09 CEST 2000
jschmitt at vmlabs.com wrote:
> Mark Hammond wrote:
> > jschmitt at vmlabs.com> wrote:
> > > I can get it to print the PATH environment variable and it
> > > tells me that things like 'grep' are in my path. Yet,
> > >
> > > cmd = os.popen( 'grep' )
> > >
> > > never launches.
> > Never launches, or launches and quickly terminates? "grep" with
> > no options will attempt to read from stdin, but no stdin it setup,
> > so it will exit immediately.
> Never seems to launch. Below is my script. If I run this, I get the
> same results as when I type 'dir' at the console. If I change to
> 'dir' to 'grep', nothing gets printed at all, not even the message
> that popen failed. When I type 'grep' on the console, I get a terse
> help message.
This help message is printed on stderr, while popen only gives
you stdout. A call to grep with no input will indeed just exit
without writing anything to stdout. The behaviour you see is
therefore exactly what you should expect: "working as designed".
If there was a "real" failure, then you'd get an exception.
The visible effects may actually be different when you try
the same thing inside a unix shell. This is because the unix
process model inherits all standard streams to child processes,
while Windows typically doesn't. As a consequence, the help
message still gets printed to the "current terminal" on unix,
while it is just lost on Windows.
Georg Mischler -- simulations developer -- schorsch at schorsch.com
+schorsch.com+ -- lighting design tools -- http://www.schorsch.com/
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list