Search code examples
phpbatch-filecmdwindows-server-2003

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?


Solution

  • 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