Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 216
Brian Webster Avatar asked Dec 30 '22 19:12

Brian Webster


2 Answers

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

like image 107
Peter Parker Avatar answered Jan 01 '23 10:01

Peter Parker


$result = `whatever.cmd`;
print $result; // Prints the result of running "whatever.cmd"
like image 32
Ian P Avatar answered Jan 01 '23 10:01

Ian P