0

i'm looking for a way in python to run an external binary and watch it's output for: "up to date" If "up to date" isn't returned i want to run the original command again, once "up to date" is displayed i would like to be able to run another script. So far I've figured out how to run the binary with options using subprocess but thats as far as I've gotten. Thanks!

bleomycin
  • 65
  • 1
  • 4
  • Duplicate: http://stackoverflow.com/questions/2082850/real-time-subprocess-popen-via-stdout-and-pipe, http://stackoverflow.com/questions/881696/unbuffered-stdout-in-python-as-in-python-u-from-within-the-program and all of the http://stackoverflow.com/search?q=python+stdout questions. – S.Lott May 19 '10 at 09:57

1 Answers1

3

Use Popen from subprocess like this

process = Popen("cmd", shell=True, bufsize=bufsize, stdout=PIPE)

Then use process.stdout to read from program's stdout (like reading from any other file like object).

Ivan
  • 1,735
  • 1
  • 17
  • 26
  • Thank you very much for the reply! So far i've managed to come up with this: http://pastebin.com/1GNAZ5bB But im unsure how to re-run if HLDS is not found, or how to call a new binary if it is? – bleomycin May 19 '10 at 10:44
  • Can't access your pastebin currently. But I'll try to answer. Each instance of POpen represents one process. So to start it again you have to create a new instance of POpen and repeat the process. – Ivan May 19 '10 at 11:43