开发者

How can I direct output from a program to fill a form on a webpage?

My 1D barcode scanner appears as an input device in Linux allowing me to fill a web page form with barcode scans exactly as if I was manually typing the input. I need to replicate this 'scan--put data into web form' behaviour 开发者_如何转开发using a 2D barcodes read from a webcam and extracted with the command line utility. The utility I'm using (zbarcam), prints the detected code to stdout whenever a barcode is detected---very nice! I need somehow to redirect that stdout stream to the current web page in my browser so I can fill in a text box with the data. This seems like a simple redirection problem but I can't figure out how to make it work. Perhaps there is a way to make a utility act as a 'virtual' input device?


Use "crikey"!

zbarcam -raw /dev/video0 | crikey -i

First, you have to download and compile "crikey", like this:

sudo apt-get install libx11-dev x11proto-xext-dev libxt-dev libxtst-dev

wget http://www.shallowsky.com/software/crikey/crikey-0.8.3.tar.gz

tar -xzf crikey-0.8.3.tar.gz

cd crikey-0.8.3

make

sudo cp crikey /usr/local/bin

Now, you got everything ready to work, capture and decode your barcode, exactly where you put the cursor.... a Gedit window, Google input box, any app...

Just type zbarcam --raw /dev/video0 | crikey -i

If the command above does NOT work, try.. zbarcam --raw /dev/video1 | crikey -i

If you got a webcam that only works with V4L1, try the following command. LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so zbarcam --raw /dev/video1 | crikey -i

or LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so zbarcam --raw /dev/video0 |crikey -i

Here you got a videoclip showing how I capture any barcode and get the result in anywhere...

http://www.youtube.com/watch?v=IPe_9bhPtT4

Enjoy! Any comment or doubt, send me an email at fmft71 at yahoo dot es

Regards

MrFMFT71


I would go this way.

First send the output of your app to a temp location, so that file will get automatically updated everytime you read a new barcode.

zbarcam <params> > /tmp/barcodeoutput

Then you would create an script like this one that will automatically using ajax and jquery refresh its contents.

index.php

<html>
<head>
    <title>jquery ajax</title>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
    <script type="text/javascript">
 $(document).ready(function() {
     $("#content").load("feed.php");
   var refreshId = setInterval(function() {
      $("#content").load('feed.php?randval='+ Math.random());
   }, 2000);
   $.ajaxSetup({ cache: false });
});
</script>
</head>
<body>

    <pre id="content">

    </pre>

</body>
</html>

And the last file would be the php file that index.php will call using ajax.

feed.php

<?php
readfile('/tmp/barcodeoutput');


?>


a better way is sending that output to a script (or a console program), which does a POST request to the web form. Perl is a good candidate for this. It is definitely harder (if you are not familiar with writing a program that does POST request), but I think it's a better way to do it.


I may help with the second part of your question: getting your program to upload data to your server or generate a web page. You need to be familiar with HTML forms (and how they are submitted with GET and POST).

Upload data directly to your server

Use libCURL in C or urllib in Python to perform a form submission. Your C or python program can simulate the action of a guy who enters values into a form and clicks submit. You just need to see the source of your web page and devise your program accordingly.

For example: response=urllib2.urlopen('http://localhost:8983?q=well&fl=id&wt=python') in python is an example of a GET request. For example, When you search hp laptop in google, it requests for the page http://www.google.co.in/#hl=en&q=hp+laptop&fp=1

Current web page-- and awful hack

That seems an awful approach, its not at all robust. But it may enter all values in your form for you. You may call a

system("browser-command url+*javascript*")

from a C program. This simulates opening a browser in command line. Chromium takes care to open the URL in a new tab. You will need to make some inline javascript code to set the values of your form.

For inline javascript code http://www.tizag.com/javascriptT/javascriptvoid.php

For learning Document Object Model (manipulating elements in your page): http://www.w3schools.com/js/js_ex_dom.asp

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜