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!

4
  • does your command ./zwmeter /dev/ttyUSB0 300 runs forever? like top command? Commented Mar 24, 2015 at 17:22
  • Sortof, it never terminates, just keeps appending lines of text to stdout Commented Mar 24, 2015 at 17:24
  • i hope this link might help bytes.com/topic/python/answers/… Commented Mar 24, 2015 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. Commented Mar 24, 2015 at 17:52

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.