Getting returncode of a command executed with Popen through xterm

A

AmFreak

Hi,

i have a program that have to execute linux commands. I do it like this:

retcode = Popen(["xterm", "-e", command],stdin=PIPE, stdout=PIPE,
stderr=PIPE)

I have to use xterm because some commands need further input from the user
after they are executed.
But when i use xterm i can't get the returncode or the errormessage from a
command:

print retcode.returncode # always 0
print retcode.stderr.read() # always empty
print retcode.stdout.read() # always empty

The same code works without xterm. As i understand it, if i use xterm the
retcode refers to the xterm window (process).
But is there a way i can get the returncode and errormessage of the
command i sent to xterm ?

Thanks for any answers

AmFreak
 
D

Diez B. Roggisch

Hi,

i have a program that have to execute linux commands. I do it like this:

retcode = Popen(["xterm", "-e", command],stdin=PIPE, stdout=PIPE,
stderr=PIPE)

I have to use xterm because some commands need further input from the
user after they are executed.
But when i use xterm i can't get the returncode or the errormessage
from a command:

print retcode.returncode # always 0
print retcode.stderr.read() # always empty
print retcode.stdout.read() # always empty

The same code works without xterm. As i understand it, if i use xterm
the retcode refers to the xterm window (process).
But is there a way i can get the returncode and errormessage of the
command i sent to xterm ?

You could create a python-wrapper-script that will store the result and
streams in files. Like this


command = ["callwrapper", "--dest-key=<random_string>", "the_real_command"]
Popen(["xterm", "-e", command])

The dest-key will be used to create files named <random_string>.status,
<random_string>.stdout, <random_string>.stderr so that you can read from
them afterwards.

Diez
 
A

AmFreak

Hi,

i have a program that have to execute linux commands. I do it like this:

retcode = Popen(["xterm", "-e", command],stdin=PIPE, stdout=PIPE,
stderr=PIPE)

I have to use xterm because some commands need further input from the
user after they are executed.
But when i use xterm i can't get the returncode or the errormessage
from a command:

print retcode.returncode # always 0
print retcode.stderr.read() # always empty
print retcode.stdout.read() # always empty

The same code works without xterm. As i understand it, if i use xterm
the retcode refers to the xterm window (process).
But is there a way i can get the returncode and errormessage of the
command i sent to xterm ?

You could create a python-wrapper-script that will store the result and
streams in files. Like this


command = ["callwrapper", "--dest-key=<random_string>",
"the_real_command"]
Popen(["xterm", "-e", command])

The dest-key will be used to create files named <random_string>.status,
<random_string>.stdout, <random_string>.stderr so that you can read from
them afterwards.

Diez


Thanks for the answer,

but i really don't know how to do it - i never wrote a wrapper, how do i
get the status, stdout and stderr ?
Can you elaborate that further or do you maybe have a link that could help
me ?
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top