问题
I want php file to run exe file and display the exe file content when user goes to a particular url. I am trying to run exe file using php function exec('abc.exe');. But I only see blank page.
Anyone know how to solve it or how to run exe file from php file correctly? Many thanks in advance.
回答1:
To access the operating system with php you do the following
$answer = shell_exec("abc.exe");
echo $answer."</br>";
The $answer string will contain the information that the abc.exe prints out or returns.
You may need to format it using explode().
回答2:
You can only run exe files if your php is runnning on a Windows machine. Futhermore, if you are on shared hostig, your hoster may have disabled the exec command.
If you are on a Windows machine, 'abc.exe' must be in the current directory or in the PATH.
To capture the output use:
exec( 'abc.exe', &$output);
echo $output;
Link to exec
回答3:
You can use VaccinalBowl code in windows, but for address .exe file, see the following example :
$answer = shell_exec("D://Downloads/software/npp.6.7.9.2.Installer.exe");
echo $answer."</br>";
回答4:
Encountered with permission problem even with 2&>1 (although chmod 777), but workaround by reading the output via saving into a file
See the example, cs_crypto is something to decrypt
<?php
$str = $_GET['pswd'];
$output = shell_exec("echo $str");
echo "<pre><font color='white'>$output</font></pre>";
//$output = shell_exec("echo ./cs_crypto de aesbase $str");
//$output = shell_exec("./cs_crypto de aesbase $str 2>&1");
exec("./cs_crypto de aesbase $str > out");
$output = shell_exec("tail -1 out");
//exec('./cs_crypto de aesbase $str', $output, $return_var);
//echo "<pre><font color='white'>$return_var</font></pre>";
echo "<pre><font color='white'>$output</font></pre>";
?>
So the final result in web
来源:https://stackoverflow.com/questions/12251634/how-to-run-abc-exe-using-php