Grab input&output of program on Windows

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Patrick L. Nolan

    Grab input&output of program on Windows

    I'm going nuts trying to port an application from Linux
    to Windows. We have a python/Tkinter script which runs
    a C++ application. It starts it with popen4 and
    communicates through the two pipes. It reads text output
    from stdout until a prompt appears, then sends commands
    through stdin.

    On Windows it seems to get all tangled up in the buffering
    of the two streams. When the script just reads stdout, it
    seems to be OK. As soon as the first command is sent to
    stdin, stdout blocks forever.

    I tried borrowing an idea from the Python Cookbok, recipe
    9.6. I made the streams nonblocking and put a call to
    select in a loop. The results were promising on Linux,
    but there was a mysterious error message on Windows.
    I think select works only for sockets, not pipes.

    This seems like the sort of thing that might be solved by
    expect. Will that work? Is there some other way?

    --
    * Patrick L. Nolan *
    * W. W. Hansen Experimental Physics Laboratory (HEPL) *
    * Stanford University *
  • Tero Pihlajakoski

    #2
    Re: Grab input&outpu t of program on Windows

    Patrick L. Nolan <pln@cosmic.sta nford.edu> wrote:[color=blue]
    > I'm going nuts trying to port an application from Linux
    > to Windows. We have a python/Tkinter script which runs
    > a C++ application. It starts it with popen4 and
    > communicates through the two pipes. It reads text output
    > from stdout until a prompt appears, then sends commands
    > through stdin.[/color]

    Sorry, if this is basic, but: Did you flush() after write()? Try using
    popen2() (there was something about popen4() on win32...), if possible
    (import popen2, etc.)?
    [color=blue]
    > On Windows it seems to get all tangled up in the buffering
    > of the two streams. When the script just reads stdout, it
    > seems to be OK. As soon as the first command is sent to
    > stdin, stdout blocks forever.[/color]
    [color=blue]
    > I tried borrowing an idea from the Python Cookbok, recipe
    > 9.6. I made the streams nonblocking and put a call to
    > select in a loop. The results were promising on Linux,
    > but there was a mysterious error message on Windows.
    > I think select works only for sockets, not pipes.[/color]
    [color=blue]
    > This seems like the sort of thing that might be solved by
    > expect. Will that work? Is there some other way?[/color]


    --

    Comment

    • Patrick L. Nolan

      #3
      Re: Grab input&amp;outpu t of program on Windows

      Tero Pihlajakoski <tepihlaj@nopaj u.spamoulu.fi> wrote:[color=blue]
      > Patrick L. Nolan <pln@cosmic.sta nford.edu> wrote:[color=green]
      >> I'm going nuts trying to port an application from Linux
      >> to Windows. We have a python/Tkinter script which runs
      >> a C++ application. It starts it with popen4 and
      >> communicates through the two pipes. It reads text output
      >> from stdout until a prompt appears, then sends commands
      >> through stdin.[/color][/color]
      [color=blue]
      > Sorry, if this is basic, but: Did you flush() after write()? Try using
      > popen2() (there was something about popen4() on win32...), if possible
      > (import popen2, etc.)?[/color]

      Thanks. I skimped on the details to avoid scaring off potential
      readers. Yes, I did try flushing the streams. I'm using
      win32pipe.popen 4() on windows and popen2.popen4() on linux.
      Win32pipe is supposed to be the one that works....

      --
      * Patrick L. Nolan *
      * W. W. Hansen Experimental Physics Laboratory (HEPL) *
      * Stanford University *

      Comment

      Working...