Passing string from python programs to external programs
debatem1 at gmail.com
Tue May 26 15:09:10 EDT 2009
On May 26, 2:12 pm, lone_eagle <icym... at gmail.com> wrote:
> Hi all,
> On Linux, I do something like this
> $ program_to_execute < input_file
> ... get some output ...
> I have the content of the input_file as a string inside a python
> program and would like to pass this string to the external program
> from inside the python program and get back the programs output in a
> string/file. Can someone tell me how to achieve this. I have been
> through the documentation for Popen, but this one beats me.
from subprocess import getstatusoutput
cmd = 'echo '
str = 'Hello World!'
status, output = getstatusoutput(cmd + repr(str))
Obviously, this is 3.x. I believe that in 2.x it was in
the commands module.
More information about the Python-list