简体   繁体   中英

run exe file on apache server

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).

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:

  1. Play safe and provide the full path to the exe , ie:

    exec("c:/someDir/my.exe");

  2. Make sure the user that apache's running under has permissions to execute the file;

  3. As you may already know, exe files run on windows systems, but not exclusively , they can run under Linux if you've wine installed;
  4. Consider using 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM