Re: Writing to process STDIN and reading its STDOUT from PHP4?

From: Date: Sat, 23 Sep 2000 21:36:46 +0000
Subject: Re: Writing to process STDIN and reading its STDOUT from PHP4?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-17340@lists.php.net to get a copy of this message
Hi Usin this For some reason this script didn't work. #!/usr/local/bin/php <? //open STDIN $fp=fopen("php://stdin","r"); while(!feof($fp)){ $data=fgets($fp,1024); } fclose($fp); //Write STDIN to the File $fw=fopen("data.txt","a+"); fwrite($fw,$data); fclose($fw); ?> Any idea ? Permissions are right, because the file is beeing created, I run the script in three ways,. ./std.php blah blah CTLR-D Or cat file|./std.php or ./std.php <blah.txt None of the above workd, the data.txt file remains EMPTY... any idea ? On Thu, 21 Sep 2000, Robert V. Zwink wrote: rzwink: http://www.php.net/manual/html/function.fopen.html rzwink: rzwink: The manual has some information about php defined constants rzwink: "php://stdin", "php://stdout", or "php://stderr" rzwink: rzwink: Does this help? rzwink: rzwink: Robert Zwink rzwink: http://zwink.levitate.org rzwink: rzwink: rzwink: ----- Original Message ----- rzwink: From: "Steve Hsieh" <steveh@eecs.umich.edu> rzwink: To: <php-general@lists.php.net> rzwink: Sent: Saturday, September 16, 2000 6:40 PM rzwink: Subject: [PHP] Writing to process STDIN and reading its STDOUT from PHP4? rzwink: rzwink: rzwink: > Can someone explain how I can send STDIN to a *process* and read its rzwink: STDOUT rzwink: > from PHP4? rzwink: > rzwink: > The only function I could find in the manual that seemed relevant was rzwink: > popen(), but the manual says that it is unidirectional only. rzwink: > rzwink: > There must be a better way than than writing to a temp file and calling rzwink: the rzwink: > process via rzwink: > popen("process < tmpfile", "r") ... I hope ? rzwink: > rzwink: > Anyone willing to provide a simple example of the best way to do this? rzwink: > Suppose, for example, I have a paragraph of text contained in variable rzwink: > $text, and I want to pass this to the STDIN of a binary called 'program' rzwink: and rzwink: > read its STDOUT back into PHP4. rzwink: > rzwink: > Thanks in advance! rzwink: > rzwink: > rzwink: > rzwink: > -- rzwink: > PHP General Mailing List (http://www.php.net/) rzwink: > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net rzwink: > For additional commands, e-mail: php-general-help@lists.php.net rzwink: > To contact the list administrators, e-mail: php-list-admin@lists.php.net rzwink: > rzwink: rzwink: rzwink: -- ------------------------------------------------ Yurais Fernández Leal, Systems Administrator Public Health Network Santiago de Cuba yurais@medired.scu.sld.cu http://www.scu.sld.cu/ Phone: (53) 226-54204 (home) (53) 226-51556 FAX: (53) 226-54204 ICQ: 33792610 ------------

« previous php.general (#17340) next »