Re: exec/system/pasthru I NEED HELP!!!!

From: Date: Thu, 15 Mar 2001 16:37:03 +0000
Subject: Re: exec/system/pasthru I NEED HELP!!!!
References: 1  Groups: php.gtk 
Request: Send a blank email to php-gtk+get-922@lists.php.net to get a copy of this message
> I need to run this program and send commands to it while its running. The > program I am running excepts keyboard input commands, but I want my program > to give it the commands it needs. Is there anyway of doing this? > > I want my program to launch a dos prgram (Does this then hangs?) and then > send commands to the same program it just launched. > > Here is my code as is: > > $result = passthru($command."& 1> output.txt 2>&1; print output.txt; > &", > $pass); For one thing - that looks strangely like a UNIX-type command line, which isn't going to work under Windows. Especially the '&' to run it in the background. (Unless they've changed things significantly under NT/2k, which I doubt) Anyway - if it is possible at all, you'll want to use popen() to do this. Of course, popen() only allows you to send data to the program, or read it from the program - not both. You may be able to redirect the output to a file and read that, depending on buffering... Check the PHP manual for info on popen() - http://www.php.net/popen But briefly: $process = popen ($command, 'w'); // to be able to send commands to it fputs ($process, "some command\r\n"); // send 'some command' followed by a crlf pclose ($process); // kill off the process You _might_ be able to use mode 'w+' to allow reading and writing, according to some of the comments in the manual. I'll leave it to you to try it... -- Michael.

« previous php.gtk (#922) next »