trouble controlling vim with subprocess on windows machine
josiah.carlson at sbcglobal.net
Wed Jul 11 05:31:44 CEST 2007
> Hi Josiah,
>>>> This recipe for asynchronous communication usingsubprocesscould be
>>>> used to write an expect-like tool:
> I have played with the above recipe and it is excellent,
> but could you please go into some more detail about what is needed
> to make a cross platform [p]expect like (non-pty based) tool?
We only get ptys. Unless you can figure out some incantation to fake
the creation of a tty (so that ssh and other software don't conmplain),
all you get is a pty.
To make it work like expect, one would (strictly speaking) need to do
the pattern matching that expect does, which may require writing a new
regular expression library.
> Specifically, could you describe how you would connect to
> *another* interactive Python process with your subclass of
> a = Popen('python', stdin=?, stdout=?, stderr=?)
> #now run an interactive session with 'a'
Some platforms have very strange buffering behavior with Python. What I
have done in my own code (for creating a Python subprocess, though not
using the subprocess module) is to do something like the following...
python_cmd = '''<path to python> -u -c "import sys; \
'use Ctrl-Break to restart *this* interpreter';import code;\
a = Popen(python_cmd, subprocess.PIPE, subprocess.PIPE)
> I have tried several combinations of the above and I seem
> to be stuck on the fact that python is interacting with a
> 'tty', not 'std*'. Maybe I'm missing a basic piece?
I've had buffering issues on certain platforms (Windows), error messages
about not having a tty (when trying to control an ssh session on *nix
and Windows), etc. Getting this to work for arbitrary programs that
expect a tty, and/or being able to query the terminal for other
information (dimension, terminal emulation, etc.), will be a chore, if
More information about the Python-list