Skip to content Skip to sidebar Skip to footer

Python Executing Shell Command Doesn't Terminate

I am using subprocess to check output of zbarcam from video device Here's my code: >>> import subprocess >>> subprocess.check_output(['zbarcam','/dev/video1']) Z

Solution 1:

The subprocess.check_output call only gives you output when the process has exited. What you want is to read the output while it's still running.

To do that you can use something like this:

import os

process =os.popen('/usr/bin/zbarcam','r')
while True:
    print'Got barcode:', process.readline()

Solution 2:

This is perfectly normal. You get the output only after command has finished.

See here:

How can I run an external command asynchronously from Python?

for a solution to run commands asynchronous.

Post a Comment for "Python Executing Shell Command Doesn't Terminate"