popen2 usage

jb jsbraich at gmail.com
Thu Jul 21 09:10:03 EDT 2005


Actually, "-test1" is a text argument that testme.exe should receive
from standard input. For example,
Executing testme.exe generates the following output,
Please select one of the following options:
1) test1
2) test2
3) exit
Please enter your option here:-test1 <-This -test1 is what user would
type

Thanks,
-JB


Steven Bethard wrote:
> jb wrote:
> > Hi there:
> >
> > I need help with popen2 usage.  I am coding on Windows 2000 environment
> > and I am basically trying to run command line executable program that
> > accepts command line arguments from user. I want to be able to provide
> > these arguments through input pipe so that executable does not require
> > any intervention from the user.  The way I am doing this is as below:
> >
> > out1, in1 = popen2.popen2("testme.exe > abc.txt")
> > in1.write('-test1')
> > in1.flush()
> > in1.close()
> >
> > But this does not seem to be working, when I open abc.txt file it does
> > not show '-test1' argument that was supplied via in1.write method. This
> > causing executable to wait forever unless user manually kills the
> > process.
>
> I'm confused; is "-test1" a command line argument to testme.exe?  Or is
> it the text that testme.exe should receive from standard input?
>
> Either way, I would suggest using subprocess instead of popen*.
>
> To pass -test1 as a command line argument, do something like:
>
> import subprocess as sp
> p = sp.Popen(["testme.exe", "-test1"], stdout=sp.PIPE)
> out1 = sp.stdout.read()
>
> To pass -test1 through standard input, do something like:
>
> import subprocess as sp
> p = sp.Popen(["testme.exe"], stdout=sp.PIPE)
> p.stdin.write("-test1")
> p.stdin.flush()
> p.stdin.close()
> out1 = p.stdout
> 
> HTH,
> 
> STeVe




More information about the Python-list mailing list