trouble controlling vim with subprocess on windows machine

Eric_Dexter at msn.com Eric_Dexter at msn.com
Tue Jul 10 19:56:07 EDT 2007


On Jul 10, 10:38 am, "Eric_Dex... at msn.com" <Eric_Dex... at msn.com>
wrote:
> On Jul 10, 4:00 am, agc <cleme... at gmail.com> wrote:
>
>
>
>
>
> > 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 withvim
> > > > it isn't clear
> > > > how I should call it..  vimfilename 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- Hide quoted text -
>
> > - Show quoted text -
>
> I gave this a shot with a windows batch file (although I am not sure I
> am doing it right)
>
> path c:\program files\vim\vim71
> path c:\dex tracker
> gvim bay-at-night.csd
> echo \intsr | gvim
> echo \<endin> | gvim
> echo :r strings.orc | gvim
> pause
>
> and it just pulls up gvim bay-at-night.csd and never does the two
> searches or pulls up the file.  I do have a windows version of sh if
> that works better.- Hide quoted text -
>
> - Show quoted text -

since there are alot of questions about subprocess I will suggest
http://www.rutherfurd.net/python/sendkeys/ this emulates the keyboard
for windows..  I am not sure if it works yet,




More information about the Python-list mailing list