Re: Grabbing the STDOUT

From: Date: Tue, 30 Mar 2004 16:15:54 +0000
Subject: Re: Grabbing the STDOUT
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-181831@lists.php.net to get a copy of this message
Brent Clark wrote:
Hi all Ive been try for sometime now, and too tried googling for an answer, to grab the STDOUT of a command. In this case the binary command is readbar The general output of readbar executed on its own is as so:
    Code 39->10005802
    IATA 2 of 5->2
    IATA 2 of 5->8
    1 barcodes found
I basically need to grab this output. Does anyone know how to send this to an array or varible.
You want to try shell_exec: http://www.php.net/manual/en/function.shell-exec.php I haven't used readbar, but if it returns plain text then PHP should be able to get the return result, like: $result = shell_exec('readbar'); Some things to consider though: do you want your webserver to have permission to execute shell commands? This COULD be a security risk, so be careful - watch your permissions. Another option is to run the readbar command from the command line and then pipe the result to PHP. I don't really know what you're trying to do here so I can't give better advice than that.
I too have tried the passthru function. Kind Regards and thanks to anyone that can help Brent Clark <?php
        $dirfile = opendir("/var/www/html/davies/Scanned");
        while(($row = readdir($dirfile)) == TRUE){
        clearstatcache();
        if($row != "." && $row != ".." && (substr($row,0,4) == "scan")){
                $filearray[] = $row;
                }
        }
        if($row == True){
        closedir($row);
        }
        foreach($filearray as $var => $key){
                system("/usr/sbin/readbar $key 2>%1");
        }
?>


« previous php.general (#181831) next »