Re: Re: Help with exec.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



and its that easy!

it took me a minute to figure out; but all I had to do was:

if (is_resource($process)) {

    for ($i = 0; $i < sizeof($src_ip); $i++) {
        fwrite($pipes[0], "$sig_desc[$i],$src_ip[$i],$dst_ip[$i]\n");
    }

    fclose($pipes[0]);
    fclose($pipes[1]);
    proc_close($process);
}

thanks.

On Wed, Mar 3, 2010 at 10:08 AM, Ian <php_list@xxxxxxxxxxxxx> wrote:
> On 03/03/2010 13:01, Paul Halliday wrote:
>> I need to pipe some data to an external application.
>>
>> I have this:
>>
>> while ($row = mysql_fetch_array($theData[0])) {
>>     $src_ip[] = $row[0];
>>     $dst_ip[] = $row[1];
>>     $sig_desc[] = $row[2];
>>
>>     $rec ++;
>>     if ( $rec == $recCount ) {
>>             break;
>>     }
>> }
>>
>> for ($i = 0; $i < sizeof($src_ip); $i++) {
>>     $tmpResult[] = "$sig_desc[$i],$src_ip[$i],$dst_ip[$i]\n";
>> }
>>
>>
>> The external program is called like:
>>
>> cat results.csv | theprogram outputfilename
>>
>> Is there a way mimic this w/o outputting $tmpResult to a file first?
>>
>> Thanks.
>>
>
> Hi,
>
> I have used this code to feed data to gpg and read back the encrypted
> result, Im sure you can adapt it to your needs.
>
> function Encrypt($data){
>
>        # http://www.theoslogic.com/scripts/php-gpg/
>
>        $gpg_command="/usr/bin/gpg $parameters";
>
>        $errLog = "/tmp/errors.log";
>
>        $dspecs = array(
>                0=>array("pipe", "r"),
>                1=>array("pipe", "w"),
>                2=>array("file", $errLog, "a")
>        );
>
>        $encrypted="";
>        $procdata="";
>
>        $gpgproc = proc_open($gpg_command, $dspecs, $pipes);
>
>        if (is_resource($gpgproc)) {
>                fwrite($pipes[0], $data);
>                fclose($pipes[0]);
>
>                while($procdata = fgets($pipes[1], 1024)) {
>                        $encrypted .= $procdata;
>                }
>                fclose($pipes[1]);
>        }
>
>        return $encrypted;
> }
>
> It works really well.
>
> Regards
>
> Ian
> --
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux