As a i'm new to the whole Piping thing and Python I had recently encountered a problem trying to pipe Cygwin's stdin & stdout into a python program usin Python's subprocess moudle. for 开发者_运维问答example I took a simple program:
cygwin = subprocess.Popen('PathToCygwin',shell=False,stdin=subprocess.PIPE,stdout=subprocess.PIPE)
cygwin.stdin.write('ssh')
After that I'm getting this error:
cygwin.stdin.write('ssh')
IOError: [Errno 22] Invalid argument
What am I doing wrong?
Well, your literal code won't work. You are passing a string with the value 'PathToCygwin' and that isn't going to do anything. I assume that you are passing a better string than that, but you didn't show us what.
I think your PathToCygwin is probably the problem. If you don't get the path right, it won't work.
Here is my test code. I ran this under the Cygwin version of Python, so I used a Cygwin-style path: instead of r"C:\cygwin\bin\bash.exe"
I used a /cygdrive/c
path:
>>> cpath = "/cygdrive/c/cygwin/bin/bash.exe"
>>> cygwin = subprocess.Popen(cpath,shell=False,stdin=subprocess.PIPE,stdout=su
bprocess.PIPE)
>>> cygwin.stdin.write("ssh")
>>>
Again, I ran this in the Cygwin-compiled version of Python. If you are using the Windows native version of Python, you will probably need to use a C:
path.
If you still are having trouble, would you please tell us exactly which version of Python you are using, and show us the actual path code you are using?
精彩评论