I've got a main process in which I run a subprocess, which stdin is what I want to pipe. I know I can do it using files:
import subprocess
subprocess.call('shell command', stdin=open('somefile','mode'))
Is there any option to use a custom stdin pipe WITHOUT actual hard drive files? Is there any option, for example, to use string list (each list element would be a newline)?
I know that python subprocess calls .readline()
on the pipe object.
First, use subprocess.Popen
- .call
is just a shortcut for it, and you'll need to access the Popen
instance so you can write to the pipe. Then pass subprocess.PIPE
flag as the stdin
kwarg. Something like:
import subprocess
proc = subprocess.Popen('shell command', stdin=subprocess.PIPE)
proc.stdin.write("my data")
http://docs.python.org/2/library/subprocess.html#subprocess.PIPE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With