I am using zbarcam to read barcode from a webcam in my webapps. But, since zbarcam display a \n at the end, my form is submit.
Here is what I use :
read_one.py
#!/usr/bin/python
from sys import argv
import zbar
import webbrowser
# create a Processor
proc = zbar.Processor()
# configure the Processor
proc.parse_config('enable')
# initialize the Processor
device = '/dev/video0'
if len(argv) > 1:
device = argv[1]
proc.init(device)
# enable the preview window
proc.visible = True
# read at least one barcode (or until window closed)
proc.process_one()
# hide the preview window
proc.visible = False
# extract results
for symbol in proc.results:
# do something useful with results
print symbol.data
keyboard.sh
python read_one.py | xvkbd -file -
How can I either remo开发者_JAVA百科ve the '\n' before sending the barcode to xvkbd or disable the enter key in xvkbd ?
Try this:
printf "$(python read_one.py)" | xvkbd -file -
To strip the enter:
print symbol.data.strip()
But a pipeable program that does that is kind of nasty. You could just send directly to xvkbd from your program (and no need for file if you don't mind passing the string in args):
import subprocess # at appropriate place
subprocess.call(['xvkbd', '-text', symbol.data.strip()])
This also avoids another shell and script to run.
精彩评论