From: tim_one at email.msn.com (Tim Peters)
Date: Sat, 24 Apr 1999 04:42:21 GMT
Subject: help with os.popen()
In-Reply-To: <7fomaj$oo9$1@nnrp1.dejanews.com>
References: <7fomaj$oo9$1@nnrp1.dejanews.com>
Message-ID: <000301be8e0c$d71ff4a0$f09e2299@tim>
Content-Length: 1391
X-UID: 1551                                                  

[cmedcoff at my-dejanews.com]
> I'm new to python and need a bit of help with os.popen().  What
> is wrong with the following? What am I doing wrong? (I'm running
> 1.52 on WinNT 4.0)
>
> >>>import os
> >>> p = os.popen("dir", "rt", 1024)
> Traceback (innermost last):
>   File "<pyshell#4>", line 1, in ?
>     p = os.popen("dir", "rt", 1024)
> OSError: (0, 'Error')
> >>>

[... and later]
> Please disregard my post.  I blew it. I found the answer in the FAQ.

No you didn't <wink>.  Seriously, the FAQ talks about PythonWin, but the
"pyshell#4" above suggests you're running IDLE.  Different beasts!

popen is a nightmare under Windows regardless, and I doubt it will ever work
without surprises.  If you try e.g.

f = os.popen("dir")

in an interactive DOS-box Python, at least under Win95 it freezes the
interpreter solid.  Run it under the MS debugger to find out why, and it
freezes the debugger solid too.  The popen call returns without incident,
but stdin and stdout are screwed up beyond recognition.  This is related to
"dir" being a command.com builtin, btw -- you don't get this problem if you
popen a random .exe.

OTOH,

f = os.popen("dir"); lines = f.readlines()

(all on one line) does work OK from a DOS-box Python.  But not under IDLE or
PythonWin.

I'll figure this all out if I ever get a free year <0.7 wink>.

pipes-break-windows-in-real-life-too-ly y'rs  - tim






