Python Subprocess module

Dan Stromberg - Datallegro dstromberg at datallegro.com
Fri Jul 13 19:50:23 EDT 2007


You could start up a pty and do your own Pexpect-like thing, using
read/readline/write.

However, this may not be portable to windows.  Maybe if you get the python
that comes with cygwin, or build your own python under the cygwin
environment - that might be more likely to get you pty's under windows.

On Fri, 13 Jul 2007 17:15:49 -0400, Dave Sampson wrote:

> hey folks,
> 
> A simple question hopefully. despite all my searching I have not found a 
> satisfactory response.
> 
> The goal. Interact with a command line program. Simple enough, but the 
> key is INTERACT.
> 
> I tried the shell and comand approaches but that initiates, it does not 
> allow interaction with the programs.
> 
> So then I went with Popen and such... which then led to the subprocess 
> module.
> 
> I can create the object and read a few lines of output. but if I go too 
> far then the program hangs. the number of lines will differ depandening 
> on many function including the format of an input file so I can;t 
> hardcode how many lines to read.
> 
> I want to read all of STDOUT without failing because I went out of range.
> 
> next I want to read the final line of the output because it tells me 
> what is required for the next line of input.
> 
> I am supposed to be able to entre 'y' and return for the program to 
> continue if I agree with what I see in the stdout.
> 
> A problem exists though that I have tried
> 'y'
> 'y\n'
> 'y\r'
> 
> and nothing seems to get the program going again for I still cant; read 
> past the same point in the standard output. then I have to kill and 
> start over.
> 
> So the next approach included looking at Pexpect, which got realy 
> confusing realy fast and despite running fedora core and python 2.4.4 I 
> would like my application to be cross platform and there is no Pexpect 
> for Windows That I can see.
> 
> I have checked  out many mailing lists and posts and tutorials but they 
> all admit to not be samples of complex interactivity. I guess I am 
> having that special case.
> 
> ASPN Python cookbok provided some code for a new Popen Class that allows 
> for interaction but I don't think I need to go that root....
> 
> I am essentialy trying to build and Python wrapper for a coomand line 
> program that i want to build a GUI around.
> 
> Any links or suggestions would be great. Unfortunaetly I don't 
> understand that abstract concepts in the manual reference. I am fresh in 
> the python world and find examples better than technical abstracts.
> 
> Cheers




More information about the Python-list mailing list