简体   繁体   中英

redirect console output to browser

I am looking for a good method to take text output from a program and use it in a PHP web application (perhaps into a form field, eventually destined for a mysql database. Truth be told, it could probably skip the form field altogether).

The program in question is zbarcam. It outputs to console (unix or windows) text from barcodes using your webcam.

I have considered simply redirecting the output from the program to a text file ( zbarcam > ~/randomfile ) , and then using ajax to scan the file every so often to bring it into the form field, but this seems horribly inefficient.

How would you go about doing this? I'd like to avoid the additional overhead of perl or python if at all possible- but I am open to suggestions using them as well.

Have a look at the system() and exec() functions.

They allow you to run a program in the context of a console and return its output for you to put in a variable and use.

<?php
// outputs the username that owns the running php/httpd process
// (on a system with the "whoami" executable in the path)
echo exec('whoami');
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM