5

I have php installed on my windows vps and available to access via port 80 and from my home PC.

Created an auto.php file which should trigger a file name Filename.exe.

Here is the code i have written (stolen from all over the net and worked on it)

<?php
exec('c:\WINDOWS\system32\cmd.exe /c START C:\xampp\htdocs\myy\Filename.exe');
    echo "Game server has been started";
?>

But when ever i click on auto.php, it does not execute, However I can see a new command prompt is opened in Task Manager, but Filename.exe is not executed.

However if i create a bat file named lets say test.bat with the following command

copy NUL test.txt

and change the ending part of the script to test.bat instead of Filename.exe

i.e.

<?php
exec('c:\WINDOWS\system32\cmd.exe /c START C:\xampp\htdocs\myy\test.bat');
    echo "Game server has been started";
?>

It does create a file named test.txt, but if i change the command to

START Filename.exe

it still doesnt get launched, am not sure what am I doing wrong here.

Please help.

My end game is to be able to launch filename.exe (is in same folder as of auto.php) to run remotely from browser..

Harsh
  • 152
  • 1
  • 1
  • 9
  • Related, [How do you run a .bat file from PHP?](http://stackoverflow.com/q/835941) – jww Nov 15 '16 at 03:54

2 Answers2

2

The php exec($cmd) function will execute your command as if it's directly put in a terminal on the server. That means you should be able to simply have

exec('START C:\xampp\htdocs\myy\Filename.exe');

And it should work.

If it still doesn't work, you can always create a batch file which contains a call to that application like

START C:\xampp\htdocs\myy\Filename.exe

On most windows systems, the START will represent the opening of a new instance of the default command prompt to run the command, it could be optional as well.

Hope it helps

RDardelet
  • 564
  • 3
  • 11
  • If i run the command you gave, that is `START C:\xampp\htdocs\myy\Filename.exe` from cmd, it works fine, but if i put it in batch file and then use php to start the bat file with this command in PHP `exec('START C:\xampp\htdocs\myy\test.bat');` it does not run, however if i keep the command like `copy NUL test.txt` in the batch, then that runs, but .exe does not run :( – Harsh Jul 12 '16 at 13:14
  • Do you see a window popup and then disappear right away? – RDardelet Jul 12 '16 at 13:20
  • Nope :( nothing like that, does not even start in Task Manager. – Harsh Jul 12 '16 at 16:50
1

here is the way I mad it work in my requirement

exec('sample.bat',$rt); the bat file is @echo off START AfterFX.exe -r E:\work\MovieMaker.jsx pause

here after start, I call the .exe file and transferred the file to run into the software. It worked for me.

yanko
  • 164
  • 9
Amal lal T L
  • 400
  • 5
  • 20