Search code examples
phpxamppexecunity-game-engineserver-side

PHP open .exe server-side


I've been trying to execute a .exe file server-side.
In other words, what I really want is after the user uploads a file to the server a .exe file (which converts this file) is executed.
I've tried opening notepad to see if the problem was on my executable file or in the php code and it doesn't run neither (although if I check the task manager I can see it has a notepad.exe process belonging to the SYSTEM user). My guess this is going against some security measure on windows
I should probably say that I'm running XAMPP on windows 7 x64.

This is what I'm doing:

exec("cd ../../ConvertObj/ && ConvertObj.exe", $data, $ret);
//for debuggging
var_dump($data);
var_dump($ret);

As you can see I'm also trying to read the output in an attempt to find the problem. Now, you're probably wondering why I tagged this as unity3d as well. This executable file is a Unity3d standalone .exe . For what i've read there is a commandline argument which allows Unity3d to run without a GUI but, unfortunately, this is a PRO only argument... I don't really mind to see the GUI on the server xD
So, the output I get (using the unity3d .exe) is

array (size=2)
    0 => string 'Mono path[0] = 'C:/xampp/htdocs/ConvertObj/ConvertObj_Data/Managed'' (length=67)
    1 => string 'Mono path[1] = 'C:/xampp/htdocs/ConvertObj/ConvertObj_Data/Mono'' (length=64)

I though it was kinda weird. My guess is windows is blocking all GUI applications on the server since dir commands work flawlessly and I think these two lines are Unity3D complaining about something... Any thoughts?


Solution

  • I've had to do this before. In a closed (lan) environment with restricted users I hacked together this.

    (for the record this isn't something I'm proud of, but it worked and continues to work to this day, I would NOT recommend this if this is for general public use)

    In XP you could just check "allow this service to interact with the desktop" on the apache service. This doesn't work in W7, Also in my experience what the comment above suggested, set the service to use the apache user... this didn't work either.

    In W7 the only way I know of to make it work was to stop running apache as a service in the services menu (set startup to manual). Then take httpd.exe and create a shortcut in your startup items.

    Also, I had to use complete absolute paths for some reason eg. c:\Progra...

    Again this is a terrible hack and 99% of the time I'd say there is going to be a better way to do what you're doing. Try rethinking your approach.