473,395 Members | 1,941 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

trouble controlling vim with subprocess on windows machine

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.

def load_instrument(instr_name, csdname):
"load an instrument using vim a path should be defined for vim
currently I am doing that with the .bat file that loads the program"
f = open('csdfile.tmp','w')
my_path = "/dex tracker"
cmd = ["gvim",csdname]
vimin = subprocess.Popen(cmd,stdin=subprocess.PIPE)#.comun icate()
[0] #, stdout = f, stderr = f, cwd = my_path )
#f.close
#x = subprocess.Popen("clear").communicate(None)[0]
innum = csr.return_unique_instr_number(csdname) - 1
cmd = """/;<start""" + str(innum) + '>' +'\n'
print(cmd)
vimin.stdin.write(cmd)
cmd = """/;<endin>""" +'\n'
vimin.stdin.communicate(cmd)
cmd = ':r ' + instr_name +'\n'
print(cmd)
vimin.stdin.write(cmd)
#vimin.stdin.write(instr_name + '\n')
cmd = instr_name + '\n'

f.close()
def load_instrument2(instr_name, csdname):
"second try uses comunicate"
cmd = ["gvim",csdname]
proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, )
cmd = """/;start""" + '\n'
proc.communicate(cmd)[0]
cmd = """/;<endin>""" + '\n'
proc.communicate(cmd)[0]
cmd = ':r ' + instr_name + '/n'
proc.communicate(cmd)[0]
proc.close()

I am calling these with

load_instrument2("""strings.orc""",'bay-at-night.csd')

and I define the path of vim in a batch file befour I call the
routines

path c:\program files\vim\vim71
python_awk_bridge.py
pause

Jul 9 '07 #1
6 2378
Er*********@msn.com <Er*********@msn.comwrote:
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.
For controlling an interactive program subprocess isn't the right
tool. Subprocess only really does one way communication - it isn't
good at conversations. I'd suggest pexpect but it doesn't work on
windows.

You appear to be doing stuff with csound. There are several python
modules out there which interface with csound - did you investigate
those?

--
Nick Craig-Wood <ni**@craig-wood.com-- http://www.craig-wood.com/nick
Jul 9 '07 #2
On Jul 9, 5:30 am, Nick Craig-Wood <n...@craig-wood.comwrote:
Eric_Dex...@msn.com <Eric_Dex...@msn.comwrote:
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.

For controlling an interactive program subprocess isn't the right
tool. Subprocess only really does one way communication - it isn't
good at conversations. I'd suggest pexpect but it doesn't work on
windows.

You appear to be doing stuff with csound. There are several python
modules out there which interface with csound - did you investigate
those?

--
Nick Craig-Wood <n...@craig-wood.com--http://www.craig-wood.com/nick
The book (as kramer would say)

https://sourceforge.net/projects/dex-tracker

I would think that the purpose for stdin is input and stdout is
output.. otherwise why have stdin?? The pyexpect does look like what
I am after but it isn't windows.. And did I mention I am willing to
cheat I have a large number of unix tools that are converted over (but
not cigwin) and will even be willing to generate a script file if I
can get it to vim when it starts up... whatever it takes regardless
of how ugly looking it is.

I did notice expect

http://expect.nist.gov/#windows
http://bmrc.berkeley.edu/people/chaffee/tcltk.html

I am not sure what to do to call the tcl stuff from python though.

Jul 9 '07 #3
Er*********@msn.com 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/Coo.../Recipe/440554

It works on both Windows and *nix.
- Josiah
Jul 9 '07 #4
On Jul 9, 11:06 am, Josiah Carlson <josiah.carl...@sbcglobal.net>
wrote:
Eric_Dex...@msn.com 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/Coo.../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()
Jul 9 '07 #5
agc wrote:
Hi Josiah,
>>>This recipe for asynchronous communication usingsubprocesscould be
used to write an expect-like tool:
http://aspn.activestate.com/ASPN/Coo.../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?
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
subprocess.Popen?
i.e:

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; \
sys.stderr=sys.__stderr__=sys.stdout;import __builtin__;\
__builtin__.quit=__builtin__.exit=\
'use Ctrl-Break to restart *this* interpreter';import code;\
code.interact(readfunc=raw_input)"'''

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
not impossible.
- Josiah
Jul 11 '07 #6
On Jul 16, 7:45 am, Yves Pouplard <yves.poupl...@free.frwrote:
On Mon, 09 Jul 2007 05:30:04 -0500, Nick Craig-Wood

<n...@craig-wood.comwrote:
Eric_Dex...@msn.com <Eric_Dex...@msn.comwrote:
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.
For controlling an interactive program subprocess isn't the right
tool. Subprocess only really does one way communication - it isn't
good at conversations. I'd suggest pexpect but it doesn't work on
windows.

pexpect works with Cygwin's python :)
You appear to be doing stuff withcsound. There are several python
modules out there which interface withcsound- did you investigate
those?- Hide quoted text -

- Show quoted text -
I managed to get it as a com object (they have an example that isn't
very good on the gvim site) and it is in csound routines as of 2pm
today... Looks like it should be easy to do with sed also but I don't
know that much about it.

Jul 16 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Marc Carter | last post by:
I am trying to rewrite a PERL automation which started a "monitoring" application on many machines, via RSH, and then multiplexed their collective outputs to stdout. In production there are lots...
9
by: Clodoaldo Pinto Neto | last post by:
Output from the shell: $ set | grep IFS IFS=$' \t\n' Output from subprocess.Popen(): "IFS=' \t\n" Both outputs for comparison:
3
by: Daniel Klein | last post by:
Here's a c routine that prints a single line : #include <stdio.h> main() { printf ("Hello World!\n"); } And now the Python program (called 'po.py') that uses 'popen2' :
12
by: Eric_Dexter | last post by:
I am trying to modify a programming example and I am coming up with two problems... first is that I can't seem to pass along the arguments to the external command (I have been able to do that with...
10
by: JD | last post by:
Hi, I want send my jobs over a whole bunch of machines (using ssh). The jobs will need to be run in the following pattern: (Machine A) (Machine B) (Machine C) Job A1 Job B1 ...
12
by: bhunter | last post by:
Hi, I've used subprocess with 2.4 several times to execute a process, wait for it to finish, and then look at its output. Now I want to spawn the process separately, later check to see if it's...
7
by: geoffbache | last post by:
Am currently being very confused over the following code on Windows import subprocess, os file = open("filename", "w") try: proc = subprocess.Popen("nosuchprogram", stdout=file) except...
0
by: Michel Lespinasse | last post by:
On Thu, Aug 28, 2008 at 10:37:48AM +0100, Tim Golden wrote: The root cause is different (subprocess has separate implementations for windows and posix), but the issues are similar. In the posix...
1
by: Mark Shewfelt | last post by:
Hello, I am attempting to use Popen() in a Windows service. I have a small Win32 .exe that I normally run through the os.popen2() function. I've written a class to work with the input and output...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.