popen3 on windows and interactive subprocesses

Brian Sturk bsturk at news.rcn.com
Thu Dec 13 21:41:54 EST 2001


>> I have a script that is run from within the editor vim.  It uses 
>> popen2.popen3 to run cmd.exe.  I then grab stdout and submit commands
>> to it via stdin. It works pretty well right now except for one thing.
>> When I spawn an *interactive* process, like ftp or cleartool I no longer
>> see anything on stdout after it's launched. Is this possibly because
>> the app is writing directly to the win32 console?  Any help/ideas greatly
>> appreciated.
> 
> It depends on the application.  It could be that it is writing
> directly to the console, but it could also just be that it is
> buffering its output since it is no longer talking directly to a
> console.  Interactive applications often show this quickly because
> they print a prompt, but no newline, and then wait for input.  The
> lack of newline prevents line buffering from flushing that line.
> 
> You'll see this issue even with Python itself unless you manually
> specify non-buffered with '-u' on the command line.
> I don't know of a good way under Windows to defeat this unless the
> application has such an option.  

Thanks for your help.

Just as test I tried running python -u in this environment and
got some output but it looked like garbage, I can look into that
so at least I can support running python with -u.  I'm wondering
if there are any Windows APIs I could use that would get me
the data?

> Under Unix, you can use something
> like a pty to make the application think it's actually talking to a
> terminal although doing so portably across systems can be a black art
> mastered by few (such as 'expect').

Under Unix I am using pty, and it works *much* better.  I also looked
at some of the python expect modules and they seem to be tailored
for unix.  The one that seemed to be general purpose ( at ftp.obsidian... )
didn't allow anonymous logins.  :(

--
.-----------------------------------------------------,-------.  
| Brian M. Sturk - http://www.nh.ultranet.com/~bsturk \ C/C++ |  .>   )\,^a__
|--------------------------|  bsturk at nh.ultranet.com   | Java | (  _ _)/ /-." ~
| http://www.telengard.com `---------------------------`------|  `( )_ )/
| Telengard Technologies Inc. -  NT/*nix UI & device drivers  | _<_s_<_s
'-------------------------------------------------------------'



More information about the Python-list mailing list