bash - Subprocess in Python 2.7 -- issuing commands into an engine -


i'm new python, , i'm given engine in bash (which takes own unique commands command line prompt or file , exercises specific functionality). want subprocess through python.

i'm able open engine subprocess.call(path, shell=true), , manually interact / input commands, cannot figure out how script unique commands input engine through python, see outputs automatically. i've tried understand of documentation, so, verbose.

ideally script of input commands in python, subprocess engine, , see output engine in python output.

again, forgive me if sounds confusing. example, i've tried:

p = subprocess.popen(path-to-engine, stdin = subprocess.pipe, stdout = subprocess.pipe, shell=true) p.stdin.write("some commands") p.stdout.readline() p.kill() 

but gives me exit code 0, , no output.

you should use .communicate() instead of .kill():

import subprocess p = subprocess.popen(     path_to_engine,     stdin=subprocess.pipe,     stdout=subprocess.pipe,     stderr=subprocess.pipe,     shell=true) p.stdin.write("some commands\n") stdout, stderr = p.communicate()  print('stdout:') print(stdout) print('stderr:') print(stderr) 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo