Getting stdout from other processes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matthias Vogelgesang

    Getting stdout from other processes

    Hello,
    as I found out, it is possible to get the output of other programs
    using os.popen() and read from it. However this method is blocking for
    server processes and programs that don't stop immediately. Has anyone
    an idea how to get the output of such programs?
  • Diez B. Roggisch

    #2
    Re: Getting stdout from other processes

    Matthias Vogelgesang schrieb:
    Hello,
    as I found out, it is possible to get the output of other programs
    using os.popen() and read from it. However this method is blocking for
    server processes and programs that don't stop immediately. Has anyone
    an idea how to get the output of such programs?
    Use either the module select to dispatch in case of arriving input on
    one of several filedescriptors , or a thread to poll the data

    Diez

    Comment

    • Miki

      #3
      Re: Getting stdout from other processes

      Hello Matthias,
      as I found out, it is possible to get the output of other programs
      using os.popen() and read from it. However this method is blocking for
      server processes and programs that don't stop immediately. Has anyone
      an idea how to get the output of such programs?
      The current "official" module to use is subprocess (pipe =
      Popen([client], stdout=PIPE))
      However if the client is sending data, reading from the pipe.stdout
      will block the server.
      If you *need* to wait, then you can use pipe.wait(), otherwise do as
      Diez suggested and have a thread
      read the client output and propagate it to the main loop (maybe using
      Queue.Queue)

      HTH,
      --
      Miki <miki.tebeka@gm ail.com>
      If it won't be simple, it simply won't be. [Hire me, source code]

      Comment

      • Matthias Vogelgesang

        #4
        Re: Getting stdout from other processes

        Hi,

        Miki wrote:
        The current "official" module to use is subprocess (pipe =
        Popen([client], stdout=PIPE))
        However if the client is sending data, reading from the pipe.stdout
        will block the server.
        If you *need* to wait, then you can use pipe.wait(), otherwise do as
        Diez suggested and have a thread
        read the client output and propagate it to the main loop (maybe using
        Queue.Queue)
        Thanks both of you for your explanations. In fact, it did the trick.

        --
        Matthias

        Comment

        Working...