473,657 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.t mp','w')
my_path = "/dex tracker"
cmd = ["gvim",csdn ame]
vimin = subprocess.Pope n(cmd,stdin=sub process.PIPE)#. comunicate()
[0] #, stdout = f, stderr = f, cwd = my_path )
#f.close
#x = subprocess.Pope n("clear").comm unicate(None)[0]
innum = csr.return_uniq ue_instr_number (csdname) - 1
cmd = """/;<start""" + str(innum) + '>' +'\n'
print(cmd)
vimin.stdin.wri te(cmd)
cmd = """/;<endin>""" +'\n'
vimin.stdin.com municate(cmd)
cmd = ':r ' + instr_name +'\n'
print(cmd)
vimin.stdin.wri te(cmd)
#vimin.stdin.wr ite(instr_name + '\n')
cmd = instr_name + '\n'

f.close()
def load_instrument 2(instr_name, csdname):
"second try uses comunicate"
cmd = ["gvim",csdn ame]
proc = subprocess.Pope n(cmd, shell=True, stdin=subproces s.PIPE, )
cmd = """/;start""" + '\n'
proc.communicat e(cmd)[0]
cmd = """/;<endin>""" + '\n'
proc.communicat e(cmd)[0]
cmd = ':r ' + instr_name + '/n'
proc.communicat e(cmd)[0]
proc.close()

I am calling these with

load_instrument 2("""strings.or c""",'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_brid ge.py
pause

Jul 9 '07 #1
6 2399
Er*********@msn .com <Er*********@ms n.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...@ms n.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_instrument 3(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(shel l, stdin=pipe.PIPE , stdout=pipe.PIP E)
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 usingsubprocess could 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.Pope n?
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__.qui t=__builtin__.e xit=\
'use Ctrl-Break to restart *this* interpreter';im port code;\
code.interact(r eadfunc=raw_inp ut)"'''

a = Popen(python_cm d, 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...@ms n.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
3393
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 of these subprocesses but here is a simplified example what I have so far (python n00b alert!) - SNIP --------- import subprocess,select,sys speakers=
9
9367
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
2082
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
10981
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 the old module and cmd is the command I wish to try) all the output seems to be returned as one line (at least when I run the program in spe). import subprocess from os import system cmd = """gawk -f altertime.awk -v time_offset=4 -v
10
2567
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 Job C1 Job A2 Job B2 etc
12
4523
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 finished, and if it is look at its output. I may want to send a signal at some point to kill the process. This seems straightforward, but it doesn't seem to be working. Here's my test case:
7
3980
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 OSError: file.close() os.remove("filename")
0
196
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 case, I only observed the issue when you using subprocess.PIPE The attached patch against subprocess.py (as shipped on debian etch, based on python version 2.4.4) seems to work for me: --- /usr/lib/python2.4/subprocess.py 2008-04-16...
1
8631
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 parameters that are passed and captured from this exe. When I use the class outside of a service using either subprocess.Popen or os.popen2 work just fine. When I use this class inside a Windows service it doesn't work. It doesn't crash the...
0
8395
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8826
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7330
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6166
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.