Python reading output from a running, external process

Discussion in 'Python' started by Brian Elmegaard, Sep 10, 2003.

  1. Hi,

    I am not sure if this is a python or a wx question. However, I am
    working on a GUI for a simulation tool written in fortran. The output
    from this program during simulation written to memory and at the end
    to a file. Probably, this is the most portable way of handling
    output(?)

    Now, if I would like to build the GUI, so every time the simulator
    writes new output to the output buffer in memory, the GUI would update
    the onscreen output, could I do that? If not, is there any way to do
    it except making a library function/dll from the application and run
    that from python?

    PS: I have taken a look at mmap, and perhaps this is what I am looking
    for? But can the file to open be the output buffer from a process? On
    windows? On unix?

    tia
    --
    Brian (remove the sport for mail)
    http://www.et.dtu.dk/staff/be
    Brian Elmegaard, Sep 10, 2003
    #1
    1. Advertising

  2. Brian Elmegaard

    Matt Goodall Guest

    On Wed, 2003-09-10 at 10:52, Brian Elmegaard wrote:
    > Hi,
    >
    > I am not sure if this is a python or a wx question. However, I am
    > working on a GUI for a simulation tool written in fortran. The output
    > from this program during simulation written to memory and at the end
    > to a file. Probably, this is the most portable way of handling
    > output(?)
    >
    > Now, if I would like to build the GUI, so every time the simulator
    > writes new output to the output buffer in memory, the GUI would update
    > the onscreen output, could I do that? If not, is there any way to do
    > it except making a library function/dll from the application and run
    > that from python?
    >
    > PS: I have taken a look at mmap, and perhaps this is what I am looking
    > for? But can the file to open be the output buffer from a process? On
    > windows? On unix?


    I'm not sure whether this will really help since your simulation tool
    writes output to memory rather than stdout but it sounds like you need
    os.popen(). See http://www.python.org/doc/current/lib/os-process.html
    and
    http://www.python.org/doc/current/lib/os-newstreams.html#os-newstreams.

    Basically, os.popen() would allow you to execute the simulation tool and
    have its output channelled back to the GUI application through a
    file-like object.

    I don't know wx much but it is generally possible to attach a file (i.e.
    the file returned by popen) to the GUI's event queue so that one of your
    event handlers is called when there is new output from the simulation
    tool. It should be easy enough to parse that to update the UI.

    Hope this helps.

    Cheers, Matt
    --
    Matt Goodall, Pollenation Internet Ltd
    w: http://www.pollenation.net
    e:
    Matt Goodall, Sep 10, 2003
    #2
    1. Advertising

  3. Brian Elmegaard

    Robert Amesz Guest

    Matt Goodall wrote:

    > Basically, os.popen() would allow you to execute the simulation
    > tool and have its output channelled back to the GUI application
    > through a file-like object.
    >
    > I don't know wx much but it is generally possible to attach a file
    > (i.e. the file returned by popen) to the GUI's event queue so that
    > one of your event handlers is called when there is new output from
    > the simulation tool. It should be easy enough to parse that to
    > update the UI.



    In my experience it is *not* a good idea to use popen() in wxPython
    apps, at least not under Windows: there seems to be some buffering
    going on in popen(), totally ruining any sense of concurrency. Also,
    reading the streams returned by popen() block, something to be avoided
    at all costs in a GUI program. Finally, the process exit code is lost
    when using popen().

    Fortunately, in wxPython you can use a wxProcess, which doesn't buffer
    or block, and can be polled using timer or idle events. There's an
    example of how to use it in the wxPython demo.


    Robert Amesz
    Robert Amesz, Sep 10, 2003
    #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. rtm
    Replies:
    0
    Views:
    797
  2. ToMasz
    Replies:
    9
    Views:
    452
    Dennis Lee Bieber
    Jan 24, 2006
  3. bingbang
    Replies:
    1
    Views:
    119
    Nobody
    Sep 30, 2011
  4. Ferenc Engard

    running external process?

    Ferenc Engard, Jan 18, 2004, in forum: Ruby
    Replies:
    5
    Views:
    113
    Ferenc Engard
    Jan 18, 2004
  5. RBCS
    Replies:
    1
    Views:
    137
    A. Sinan Unur
    Feb 14, 2006
Loading...

Share This Page