Forum Moderators: coopster
Here's the code I've tried using:
exec("cmd /K test.bat"); The PHP script that contains the code above hangs when executed. What is the correct way to do this?
Or is there a way to have PHP display the output from the .bat file on the fly (as opposed to waiting for the .bat file to execute THEN dump the output?)
-p
/C Carries out the command specified by string and then terminates
/K Carries out the command specified by string but remains
Or to display the output on the fly, try:
$pp = popen("cmd /c test.bat", "r");
while ($s = fgets($pp)) {
print "$s";
}
pclose($pp);
For the sake of debugging, I emptied out test.bat just to make sure it's not the contents that are causing PHP to hang, but unfortunately PHP is still hanging.
Using the popen method produces the same result - PHP hanging.
Any idea as to what the problem might be?
exec("test.bat");
echo exec("test.bat");
$pp = popen("test.bat", "r");
while ($s = fgets($pp)) {
print $s;
}
pclose($pp);