zbarcam はコードを読み取った後に自動的に終了しないため、zbarcam を使用してバーコードを読み取ります。
私の parking-mng.py ファイルは次のとおりです。
#!/usr/bin/python
import subprocess
import MySQLdb as db
from config import *
import sys
temp = ''
def scanfun():
subprocess.call("./k.sh")
reg = sys.stdin.readline().strip()
con = None
con = mdb.connect(server, user, pwd, database);
cur = con.cursor()
print "successful"
while(1):
print "------Parking Sector 11----------"
print "Select : "
print """1. Scan Code\n2. Update Balance\n3. Exit\n"""
choice = raw_input()
if choice == '1':
scanfun()
else:
break
ここに私の k.sh ファイルがあります:
#!/bin/bash
tmp=/tmp/barcode.$$
zbarcam --raw /dev/video1 > $tmp &
pid=$!
# Sleep until file has content
while [[ ! -s $tmp ]] ; do
sleep 1
done
kill $pid
cat $tmp | ./parking-mng.py
問題は、print ステートメントが機能せず、端末に何も出力されないことです。