popen2 usage

J

jb

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.

Please help

Regards,
jb
 
S

Steven Bethard

jb said:
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
 
J

jb

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 said:
jb said:
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
 
D

Dennis Lee Bieber

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
Why would the user type the hyphen? Your prompt seems to imply
that the user should type JUST "1", "2", or "3" (or, if the numbers are
meaningless, "test1", "test2", "exit" with no "-").

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top