FAQ
I have a script that is run from within the editor vim. It uses
popen2.popen3 to run cmd.exe. I then grab stdout and submit commands
to it via stdin. It works pretty well right now except for one thing.
When I spawn an *interactive* process, like ftp or cleartool I no longer
see anything on stdout after it's launched. Is this possibly because
the app is writing directly to the win32 console? Any help/ideas greatly
appreciated.

<pushing_wares>
The script, for those curious vim users, is located here:

http://www.nh.ultranet.com/~bsturk/vim.html
</pushing_wares>

--
.-----------------------------------------------------,-------.
Brian M. Sturk - http://www.nh.ultranet.com/~bsturk \ C/C++ | .> )\,^a__
--------------------------| bsturk at nh.ultranet.com | Java | ( _ _)/ /-." ~
http://www.telengard.com `---------------------------`------| `( )_ )/
Telengard Technologies Inc. - NT/*nix UI & device drivers | _<_s_<_s
'-------------------------------------------------------------'

Search Discussions

  • David Bolen at Dec 13, 2001 at 8:10 pm

    bsturk at news.rcn.com (Brian Sturk) writes:

    I have a script that is run from within the editor vim. It uses
    popen2.popen3 to run cmd.exe. I then grab stdout and submit commands
    to it via stdin. It works pretty well right now except for one thing.
    When I spawn an *interactive* process, like ftp or cleartool I no longer
    see anything on stdout after it's launched. Is this possibly because
    the app is writing directly to the win32 console? Any help/ideas greatly
    appreciated.
    It depends on the application. It could be that it is writing
    directly to the console, but it could also just be that it is
    buffering its output since it is no longer talking directly to a
    console. Interactive applications often show this quickly because
    they print a prompt, but no newline, and then wait for input. The
    lack of newline prevents line buffering from flushing that line.

    You'll see this issue even with Python itself unless you manually
    specify non-buffered with '-u' on the command line.

    I don't know of a good way under Windows to defeat this unless the
    application has such an option. Under Unix, you can use something
    like a pty to make the application think it's actually talking to a
    terminal although doing so portably across systems can be a black art
    mastered by few (such as 'expect').

    --
    -- David
    --
    /-----------------------------------------------------------------------\
    \ David Bolen \ E-mail: db3l at fitlinxx.com /
    FitLinxx, Inc. \ Phone: (203) 708-5192 |
    / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \
    \-----------------------------------------------------------------------/
  • Brian Sturk at Dec 14, 2001 at 2:41 am

    I have a script that is run from within the editor vim. It uses
    popen2.popen3 to run cmd.exe. I then grab stdout and submit commands
    to it via stdin. It works pretty well right now except for one thing.
    When I spawn an *interactive* process, like ftp or cleartool I no longer
    see anything on stdout after it's launched. Is this possibly because
    the app is writing directly to the win32 console? Any help/ideas greatly
    appreciated.
    It depends on the application. It could be that it is writing
    directly to the console, but it could also just be that it is
    buffering its output since it is no longer talking directly to a
    console. Interactive applications often show this quickly because
    they print a prompt, but no newline, and then wait for input. The
    lack of newline prevents line buffering from flushing that line.

    You'll see this issue even with Python itself unless you manually
    specify non-buffered with '-u' on the command line.
    I don't know of a good way under Windows to defeat this unless the
    application has such an option.
    Thanks for your help.

    Just as test I tried running python -u in this environment and
    got some output but it looked like garbage, I can look into that
    so at least I can support running python with -u. I'm wondering
    if there are any Windows APIs I could use that would get me
    the data?
    Under Unix, you can use something
    like a pty to make the application think it's actually talking to a
    terminal although doing so portably across systems can be a black art
    mastered by few (such as 'expect').
    Under Unix I am using pty, and it works *much* better. I also looked
    at some of the python expect modules and they seem to be tailored
    for unix. The one that seemed to be general purpose ( at ftp.obsidian... )
    didn't allow anonymous logins. :(

    --
    .-----------------------------------------------------,-------.
    Brian M. Sturk - http://www.nh.ultranet.com/~bsturk \ C/C++ | .> )\,^a__
    --------------------------| bsturk at nh.ultranet.com | Java | ( _ _)/ /-." ~
    http://www.telengard.com `---------------------------`------| `( )_ )/
    Telengard Technologies Inc. - NT/*nix UI & device drivers | _<_s_<_s
    '-------------------------------------------------------------'
  • David Bolen at Dec 14, 2001 at 3:01 am

    bsturk at news.rcn.com (Brian Sturk) writes:

    Just as test I tried running python -u in this environment and
    got some output but it looked like garbage, I can look into that
    so at least I can support running python with -u. I'm wondering
    if there are any Windows APIs I could use that would get me
    the data?
    I don't think so - regardless of how you execute and connect to the
    process (the popen() calls under Windows eventually just call
    CreateProcess anyway), it's the executed application itself that is
    making the buffering choices based on the file handle representing
    stdin. So unless the application itself provides some control over
    this, there's very little you can do from the outside, Windows API or
    not.

    --
    -- David
    --
    /-----------------------------------------------------------------------\
    \ David Bolen \ E-mail: db3l at fitlinxx.com /
    FitLinxx, Inc. \ Phone: (203) 708-5192 |
    / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \
    \-----------------------------------------------------------------------/

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedDec 13, '01 at 7:59a
activeDec 14, '01 at 3:01a
posts4
users2
websitepython.org

2 users in discussion

David Bolen: 2 posts Brian Sturk: 2 posts

People

Translate

site design / logo © 2022 Grokbase