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

From: Date: Thu, 15 Mar 2001 17:57:10 +0000
Subject: Re: exec/system/pasthru I NEED HELP!!!!
References: 1  Groups: php.gtk 
Request: Send a blank email to php-gtk+get-934@lists.php.net to get a copy of this message
> works > $process = popen ($command, 'w'); // to be able to send commands to it > > Not working! > fputs ($process, "some command\r\n"); // send 'some command' [...] I just tried quickly with 'dir /p' - couldn't get it to work. Bi-directional pipes clearly don't work on Win32 (unsurprisingly) The closest I got was running 'dir /p > something.txt' and then reading something.txt for the output, and sending a CR when it prompted for you to press a key. This didn't get anywhere - it appears that dir hung until I hit CTRL-BREAK, at which point PHP continued... The script I tried was 'foo.php', as follows: ------------------------------------------------------------------------------- <?php $command = 'dir /p > something.txt'; $psfd = popen ($command, 'w') or die ("Unable to exec '$command'\n"); print "popen($command) done.\n"; fputs ($psfd, "\r"); $infd = fopen ('something.txt', 'r') or die("Unable to read something.txt\n"); print "Opened something.txt\n"; while ($in = fgets($infd, 4096)) { print "In: $in"; if (ereg('^Press any key', $in)) fputs ($psfd, "\n"); } pclose ($psfd); fclose ($infd); unlink ('something.txt'); ?> ------------------------------------------------------------------------------- When I run it, it sits and does nothing until I hit Ctrl+Break, at which point it prints the "popen($command) done." line. > Is pclose supposed to close the prog. priginaly opened in this case? > if so this does not work either! It might, it might not. I think it does under *NIX, but I'm not entirely sure - I don't think I've ever pclose()'d a process I thought would still be running... I really think PHP needs some good Win32 IPC functions... or we could all just get a Real OS ;-) -- Michael.

« previous php.gtk (#934) next »