[EMAIL PROTECTED] wrote: > On Jul 9, 11:06 am, Josiah Carlson <[EMAIL PROTECTED]> > wrote: >> [EMAIL PROTECTED] wrote: >>> I am having trouble contolling vim with subprocess on a windows >>> machine. It appears that vim comes up on the machine all right and it >>> sometimes looks like it is doing the searchs what I am asking it to do >>> but when I am asking it to load a file it doesn't do anything. Is >>> there something I need to do to push the data through the pipe?? Here >>> is a couple different ways I am trying to do it. >> [snip] >> >> This recipe for asynchronous communication using subprocess could be >> used to write an expect-like tool: >> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440554 >> >> 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 -- http://mail.python.org/mailman/listinfo/python-list