Getting returncode of a command executed with Popen through xterm

Discussion in 'Python' started by AmFreak@web.de, Oct 19, 2010.

  1. Guest

    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
     
    , Oct 19, 2010
    #1
    1. Advertising

  2. writes:

    > 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
     
    Diez B. Roggisch, Oct 19, 2010
    #2
    1. Advertising

  3. Guest

    Am 19.10.2010, 10:10 Uhr, schrieb Diez B. Roggisch <>:

    > writes:
    >
    >> 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 ?
     
    , Oct 19, 2010
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sami Viitanen
    Replies:
    1
    Views:
    352
    Fredrik Lundh
    Aug 7, 2003
  2. Corey Wallis

    subprocess returncode always None

    Corey Wallis, Jul 9, 2006, in forum: Python
    Replies:
    0
    Views:
    375
    Corey Wallis
    Jul 9, 2006
  3. 7stud
    Replies:
    4
    Views:
    509
    7stud
    Sep 21, 2007
  4. Andrew

    subprocess returncode windows

    Andrew, Dec 16, 2008, in forum: Python
    Replies:
    4
    Views:
    2,054
    Andrew
    Feb 6, 2009
  5. Emmanuel

    subprocess returncode is masked

    Emmanuel, Dec 28, 2009, in forum: Python
    Replies:
    7
    Views:
    396
    Yinon Ehrlich
    Dec 31, 2009
Loading...

Share This Page