trouble controlling vim with subprocess on windows machine

agc clemesha at gmail.com
Tue Jul 10 05:00:13 EDT 2007


Hi Josiah,

> >> This recipe for asynchronous communication usingsubprocesscould be
> >> used to write an expect-like tool:
> >>    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440554

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?

Specifically, could you describe how you would connect to
*another* interactive Python process with your subclass of
subprocess.Popen?
i.e:

a = Popen('python', stdin=?, stdout=?, stderr=?)
#now run an interactive session with 'a'

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?

Thanks for any input,
Alex


> >> It works on both Windows and *nix.
>
> >>   - Josiah
>
> > I had the original dir work but when I tried to trade it out with vim
> > it isn't clear
> > how I should call it..  vim filename and it doesn't find filename for
> > some reason.
> > I called it pipe and then
>
> > inport pipe
>
> > def load_instrument3(instr_name, csd_name):
> >   if sys.platform == 'win32':
> >         shell, commands, tail = ('gvim' + csd_name, (csd_name,
> > csd_name), '\r\n')
> >   else:
> >         shell, commands, tail = ('sh', ('ls', 'echo HELLO WORLD'),
> > '\n')
>
> >   a = pipe.Popen(shell, stdin=pipe.PIPE, stdout=pipe.PIPE)
> >   print pipe.recv_some(a),
> >   for cmd in commands:
> >         pipe.send_all(a, csd_name)
> >         print pipe.recv_some(a),
> >   pipe.send_all(a, csd_name)
> >   print pipe.recv_some(a, e=0)
> >   a.wait()
>
> The example uses a platform-specific shell in order to use the
> environment variable PATH to discover the executable to run.  If you
> know the exact path to your binary ('gvim' for you), it should work.
> As-is, your program would require a binary with the name 'gvim'+csd_name
> in the same path as the script you are executing.
>
>   - Josiah





More information about the Python-list mailing list