Web lists-archives.com

Re: [PHP] Getting PHP to process input from STDIN




On Sun, Jan 24, 2016 at 12:56 PM, David OBrien <dgobrien@xxxxxxxxx> wrote:

>
>
> On Sun, Jan 24, 2016 at 12:40 PM, Danny <mynixmail@xxxxxxxxx> wrote:
>
>> Hi,
>>
>> I am trying to process the body of a message that is piped from Procmail
>> to a
>> php-cli script with no luck ... I am trying to only catch the body of the
>> message ... no other formatting ... mime etc ... only the body which
>> consists of
>> a one line message that is max 96 characters long ... the message in the
>> body
>> will start with a 0(zero) and end with a 0(zero) ...
>>
>> Here is my script:
>>
>> ######################################################################################################
>> #!/usr/bin/php
>> <?php
>>   $get_mail_body = fopen ( 'php://stdin', 'r' ) ;
>>   $mail_body = preg_match ( "/[0]*?[0]/", @$get_mail_body, $body_match,
>> PREG_OFFSET_CAPTURE ) ;
>>
>>   while ( $message = fgets ( $get_mail_body ) )
>>     {
>>         if ( $message == $body_match[0] )
>>                 {
>>                         $command = exec ( 'echo -e "\rLT
>> 4>'.$body_match[0].'r\r" > /dev/ttyS1' ) ;
>>                 }
>>         else
>>                 {
>>                 }
>>     }
>>   echo "$command" ;
>>
>>   fclose( $get_mail_body );
>> ?>
>>
>> ######################################################################################################
>>
>> And here is my procmail recipe:
>>
>> ######################################################################################################
>> :0
>> * ^Subject.*Aprs message$
>> {
>> :0 bf
>> ! `/usr/bin/php -f /usr/local/bin/scripts/aprs_messages.php`
>> }
>>
>> ######################################################################################################
>>
>> Any pointers?
>>
>> Thank You
>>
>> Danny
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
>
your just opening the pipe not reading it...

http://php.net/manual/en/features.commandline.io-streams.php

If you want to read single line from *stdin*, you can use
<?php
$line = trim(fgets(STDIN)); // reads one line from STDIN
fscanf(STDIN, "%d\n", $number); // reads number from STDIN
?>