How to catch streaming output (file in c++) from terminal to a file in python without changing the c++ file? -


this python code edited

import os     while true:     command=input("entre command:")     if command==1:             os.system("sudo python led_test.py")     elif command==2:             os.system("sudo /home/abhi/rpi_x4driver_final/rpi_x4driver/runme")     elif command==3:             os.system("aplay /home/abhi/c_music.wav") 

.the output coming command==2 needs saved in files(dynamic names) each containing 200 lines.this means want make batches of outputs coming

os.system("sudo /home/abhi/rpi_x4driver_final/rpi_x4driver/runme") 

and save them in files dynamic names.

i have tried code doesn't work

command=input("entre command:") if command==1:     sys.exit() elif command==2: proc =  subprocess.popen(["sudo/home/abhi/rpi_x4driver_final/rpi_x4driver/runme"],  stdout=subprocess.pipe)  while true:     line = proc.stdout.readline()     if line != '':         # save file instead of printing         print "test:", line.rstrip()     else:         break 

  1. if want extract part of output stream , save it, consider using subprocess.check_out follow:

    import subprocess  s = subprocess.check_out(['path/to/the/executable','-option'])  s.decode('utf-8') 
  2. if don't care extracting, consider using shell redirection suggested @someprogrammerdude > redirection in shell. more details here : http://www.tldp.org/ldp/abs/html/io-redirection.html


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -