0
`import subprocess
subprocess.check_call(
['/home/kadia/tensorflow/bazelbin/tensorflow/examples/label_image/label_image',
'--graph=/home/kadia/Desktop/TrainedShadowModel-1/output_graph.pb',
'--labels=/home/kadia/Desktop/TrainedShadowModel-1/output_labels.txt',
'--output_layer=final_result',
'--input_layer=Mul',
'--image=/home/kadia/Desktop/2.jpg']`

How can I print the output from this? Output right now going in console. I want to save the output in file

Neel Kadia
  • 77
  • 1
  • 10
  • Possible duplicate of [Running shell command from Python and capturing the output](https://stackoverflow.com/questions/4760215/running-shell-command-from-python-and-capturing-the-output) – Nick Chapman Jul 06 '17 at 08:53

1 Answers1

0

You can use popen:

from subprocess import Popen, PIPE

    p = Popen(['/home/kadia/tensorflow/bazelbin/tensorflow/examples/label_image/label_image',
'--graph=/home/kadia/Desktop/TrainedShadowModel-1/output_graph.pb',
'--labels=/home/kadia/Desktop/TrainedShadowModel-1/output_labels.txt',
'--output_layer=final_result',
'--input_layer=Mul',
'--image=/home/kadia/Desktop/2.jpg'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
    output, err = p.communicate(b"input data that is passed to subprocess' stdin")
    rc = p.returncode
lapinkoira
  • 8,320
  • 9
  • 51
  • 94
  • I'm new to python. Can you formulate code for me which I can run, based on my process which I shared in Question. I've tired but won't able to run it. – Neel Kadia Jul 06 '17 at 10:17
  • I edited my answer. Can you try like this? Assuming the command is correct – lapinkoira Jul 06 '17 at 13:00