0

I am using subprocess to check output of zbarcam from video device

Here's my code:

>>> import subprocess
>>> subprocess.check_output(["zbarcam","/dev/video1"])

Zbarcam initiates a window on which I can check the video, the problem is it keeps running even if it has read the code, and I have to manually shut this window before it outputs anything to the python shell.

Kartik Anand
  • 4,513
  • 5
  • 41
  • 72

2 Answers2

0

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()
Wolph
  • 78,177
  • 11
  • 137
  • 148
0

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.

Community
  • 1
  • 1
Dirk Stöcker
  • 1,628
  • 1
  • 12
  • 23