我使用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
問題是打印語句不工作,沒有什麼是越來越印終點站。
您的腳本可能在readline()上等待,因爲stdin上沒有'\ n'。 – Chronial 2013-04-28 16:33:21
@Chronial不,它不是因爲我能夠在打印語句後更新數據庫,它可能是打印到終端以外的地方。我不知道爲什麼 – 2013-04-28 16:34:22
@Chronial在'scanfun()'結束while循環再次進入和'print'後結束------停車扇區11 ----------「'正在顯示,只有scanfun()內部沒有顯示。 – 2013-04-28 16:38:08