Hướng dẫn run exe from php

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.

asked Sep 3, 2012 at 16:52

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

answered Sep 3, 2012 at 16:54

1

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

answered Sep 3, 2012 at 16:55

JvdBergJvdBerg

21.6k8 gold badges35 silver badges54 bronze badges

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>";

Bioukh

1,7781 gold badge15 silver badges25 bronze badges

answered Feb 5, 2016 at 9:40

I know this answer might be late but there is a "hack" in php you can use with Task Scheduler in Windows. The following code works and works with all browsers not just IE. However I should warn you that sometimes the program you are accessing may not run at that instant in time sometimes as I've noticed sometimes that the scheduled task may be in a "queued" state and not running. But the code does work 100%...it is just a matter of what state the task is in in task scheduler...either its "running" or "queued".

<?php
function ex($command)
{
    shell_exec('SCHTASKS /F /Create /TN _law /TR "' . $command . '"" /SC DAILY /RU 
INTERACTIVE');
    shell_exec('SCHTASKS /RUN /TN "_law');
    shell_exec('SCHTASKS /DELETE /TN "_law" /F');
}
ex("C:/Windows/System32/notepad.exe");
?>

answered May 24, 2020 at 8:33

2

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

Hướng dẫn run exe from php

answered Jun 29, 2018 at 6:27

Hướng dẫn run exe from php

LinconFiveLinconFive

1,4521 gold badge17 silver badges24 bronze badges