passing commands to application CLI from python script -


this question has answer here:

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.

  1. how pass commands application cli python script?
  2. 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

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -