How to run a .cmd file from within PHP and display the results

Brian Webster picture Brian Webster · Jul 18, 2009 · Viewed 8.7k times · Source

I need to run a .cmd batch file from within a php script.

The PHP will be accessed via an authenticated session within a browser.

When I run the .cmd file from the desktop of the server, it spits out some output to cmd.exe.

I'd like to route this output back to the php page.

Is this doable?

Answer

Peter Parker picture Peter Parker · Jul 18, 2009

Yes it is doable. You can use

exec("mycommand.cmd", &$outputArray);

and print the content of the array:

echo implode("\n", $outputArray);

look here for more info