0

I have a script that reads from external sensors (and runs forever), when I run it as ./zwmeter /dev/ttyUSB0 300 it behaves normally and prints output continuously to stdout. I am using bash on Ubuntu. I'd like to execute this command as part of a python script. I have tried:

from subprocess import Popen, PIPE                                   
proc = Popen(['./zwmeter', '/dev/ttyUSB0', '300'], stderr=PIPE, stdout=PIPE)                                     
print proc.communicate()

but I get a program that runs forever without producing any output. I don't care about stderr, only stdout and have tried splitting up the printing but still with no success.

Thank you for any help you can provide!

sma
  • 31
  • 1
  • 3
  • does your command `./zwmeter /dev/ttyUSB0 300` runs forever? like `top` command? – Bad_Coder Mar 24 '15 at 17:22
  • Sortof, it never terminates, just keeps appending lines of text to stdout – sma Mar 24 '15 at 17:24
  • i hope this link might help http://bytes.com/topic/python/answers/672518-using-subprocess-non-terminating-command – Bad_Coder Mar 24 '15 at 17:34
  • Thanks, that's helpful but I actually want it to run forever and be able to communicate with it during that time. I found a good solution and posted the link as an answer. – sma Mar 24 '15 at 17:52

1 Answers1

0

I think the problem has to do with the process I'm calling not terminating. I found a good work around on this site: http://eyalarubas.com/python-subproc-nonblock.html

sma
  • 31
  • 1
  • 3
  • [Are answers that just contain links elsewhere really “good answers”?](http://meta.stackexchange.com/q/8231/137096) – jfs Mar 24 '15 at 18:45