Reputation: 3046
Should it be possible to put an exe file on an apache server, send a text file via a php form, have the exe process the text file and then send the results back to the client?
Or is this generally not possible (if so, why)?
I looked around a bit but I havent really gotten a conclusive answer. Some say you should use the exe as a cgi script and some say it's only possible on a windows server.
Thanks!
EDIT
My code:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
echo exec('whoami');
echo exec("my.exe");
echo "<h1>Success</h1>";
?>
</body>
</html>
Works locally. Should this also work on an apache server hosted by a webspace company? (provided that they didn't prohibit exec).
Upvotes: 2
Views: 4296
Reputation: 98901
Or is this generally not possible (if so, why)?
There's no "generally", it depends on how apache is configured by your host provider. If you've a vps
or a dedicated server
the "generally" is what you want.
Some points to consider:
Play safe and provide the full path to the exe
, i.e.:
exec("c:/someDir/my.exe");
Make sure the user that apache's running under has permissions to execute the file;
exe
files run on windows systems, but not
exclusively, they can run under Linux if you've wine installed;shell_exec
instead of exec
, why? shell_exec
returns
all of the output stream as a string. exec
returns the last line
of the output by default, but can provide all output as an array
specified as the second parameter;Upvotes: 5