As part of my troubleshooting of being unable to launch SRCDS (the dedicated server for the Source game engine), I decided to try out launching some other executables (specifically Chrome and Firefox). Neither of those were launched, however. The page loaded (didn't hang as it does with SRCDS), but when checking Windows Task Manager, the processes were never actually launched. $output is a 0-length array, $return_var is 1 (giving me no information on the actual error happening.
The code I use is (no change occurs when using system
or passthru
instead of exec
):
<?php
// Save the current working directory, then set it to SRCDS' directory
$old_path = getcwd();
chdir("C:/Users/Johan/Desktop/SteamCMD/tf2/");
// Launch SRCDS. Only the 3rd exec allows the page to load.
//$tmp = exec("srcds -console -game tf +map ctf_2fort 2>&1",$output,$output2);
//$tmp = exec("srcds -console -game tf +map ctf_2fort >> tmp.txt",$output,$output2);
$tmp = exec("srcds -console -game tf +map ctf_2fort 1>/dev/null/ 2/&1",$output,$output2);
echo "<p>SRCDS Output: ".sizeof($output)."</p>";
echo "<p>SRCDS Output2: ".$output2."</p>";
// Test execution of other files
// test.bat echoes %time%
$tmp2 = exec("test.bat");
echo $tmp2;
// Trying to launch another executable
chdir("C:\Program Files (x86)\Mozilla Firefox");
$tmp2 = exec("firefox", $output, $output2);
echo $tmp2;
echo "<p>FF Output:".sizeof($output)."</p>";
echo "<p>FF Output2:".$output2."</p>";
// End
chdir($old_path);
echo "Done.";
?>
This outputs:
SRCDS Output: 0
SRCDS Output2: 1
0:47:59,79
FF Output:0
FF Output2:1
Done.
My question is, is there any reason for this? Am I doing this incorrectly?
/dev/null
on a Windows system, which won't work (use> nul
instead) and the correct syntax for redirecting STDERR to STDOUT on *nix and Windows is2>&1
. Also note that simply redirecting output is not enough to launch programs asynchronously, which I imagine is what you are trying to do. To do this on Windows you will needCOM
available. – DaveRandom Jul 9 at 22:542/&1
got in there, thanks for pointing it out. When using ` > nul` the page hangs, and never loads - just as what happens with all the other examples. The user PHP is run under is SYSTEM, so I'd assume it does. I'll have a look at COM - thanks a lot! – Birjolaxew Jul 9 at 23:04