Jump to content

Python input is the command prompt output from a seperate software

EoinP

So i found this greta opensource software called Zbar. It scans a barcode from a camera, and displays that code in its command-line or command-prompt. Now that i am able to scan the barcode i want to be able to find the file that is named as that barcode.

 

Example: I scan a barcode and the code is 1234567890   This outputs this number onto its command prompt style interface. Is there any way i could use python or some software to take this as an input? If i can get python to take it as an input i can then search for a filename of that number, then display it. 

 

I have a code working already for finding a specific file name, all i need is a way to input the software's output.

 

Many thanks

 

Eoin.

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, James Evens said:

Your code is already python? just use there python (pyzbar) implementation. If you don't require python user ther c++ code.

Thanks for your answer. And how would I implement this? 

Thanks, Eoin

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, M.Yurizaki said:

From what I recall, what modern barcode scanners send mimics keyboard commands for easier entry into things like spreadsheets.

 

If that's the case, then all you have to do is have a Python script accept an input and the barcode scanner should "type" the code in.

Hi, thanks for your reply! This is what i was planning on doing. The files will be accessed regularly from a specific computer so have python open to scan the file is no biggie! Do you know of any ways to make python find the output and place it in a variable?

 

Many thanks

 

Eoin.

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, EoinP said:

Hi, thanks for your reply! This is what i was planning on doing. The files will be accessed regularly from a specific computer so have python open to scan the file is no biggie! Do you know of any ways to make python find the output and place it in a variable?

 

Many thanks

 

Eoin.

The output of the barcode scanner?

 

As I said usually it's more or less mimicking a keyboard. So if you input or raw_input (for Python 2.7) or eval(input()) or input() (for Python 3) then when the script waits for the user to input something, you scan something in and the barcode scanner should send the value to the prompt.

Link to comment
Share on other sites

Link to post
Share on other sites

You could either pipe the output from the program to a python script or use the subprocess module to run the program from the python script and capture the output that way.

 

To pipe the output, from the command line you would run

 

BarcodeReader.exe | py my_python_script.py

 

where my_python_script.py is using the input() function to get input.

 

Or using the subprocess module make a script that does something like:

import subprocess as sp

proc = sp.Popen(['path/to/barcodereader.exe'], stdout=sp.PIPE)
out = proc.stdout.read()
print(out)

 

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

  • 3 weeks later...

In a unix shell you could run a command and pipe its output as the input of another command. This way you could run the barcode scanner and have it's output serve as the input for your python script. It'd look something like:

/path/to/zbar | py path/to/py_script

Then you can alias it or change it into a script so you can run it as a single command.

Edit: this will require you knowing how to read standard input in Python, but here's a stackoverflow link. And it'd only work in a shell that supports piping

 

Also https://pypi.org/project/zbar-py/

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×