passing commands to application CLI from python script -
this question has answer here:
- how give input streams in python? 2 answers
to run shell command python script, use subprocess or os.system module.
using running shell command python script initiating application , application has command line interface.
- how pass commands application cli python script?
- how can capture output of application cli python script?
it highly appreciated if can suggest material or example code.
the application you're initiating might behave differently when running through subprocess. specifically, when connected process pipe, applications buffer output default instead of flushing line line. if application you're running flushes output, can realtime, otherwise, you'll output when buffer full.
that said, here's example run application:
p = subprocess.popen(['someapp', 'param1', 'param2'], stdin=subprocess.pipe, stdout=subprocess.pipe,) # sends command "some_command" app: p.stdin.write('some_command\n') # waits single line output result = p.stdout.readline() if hangs on p.stdout.readline() means output being buffered.
Comments
Post a Comment