如何使用 php 运行 abc.exe
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12251634/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run abc.exe using php
提问by ATZ
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.
我希望 php 文件运行 exe 文件并在用户转到特定 url 时显示 exe 文件内容。我正在尝试使用 php 函数 exec('abc.exe'); 运行 exe 文件。但我只看到空白页。
Anyone know how to solve it or how to run exe file from php file correctly? Many thanks in advance.
任何人都知道如何解决它或如何从php文件正确运行exe文件?提前谢谢了。
回答by KennyBartMan
To access the operating system with php you do the following
要使用 php 访问操作系统,请执行以下操作
$answer = shell_exec("abc.exe");
echo $answer."</br>";
The $answer string will contain the information that the abc.exe prints out or returns.
$answer 字符串将包含 abc.exe 打印或返回的信息。
You may need to format it using explode().
您可能需要使用explode() 对其进行格式化。
回答by JvdBerg
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.
如果您的 php 在 Windows 机器上运行,您只能运行 exe 文件。此外,如果您在共享主机上,您的主机可能已禁用 exec 命令。
If you are on a Windows machine, 'abc.exe' must be in the current directory or in the PATH.
如果您使用的是 Windows 计算机,则“abc.exe”必须位于当前目录或 PATH 中。
To capture the output use:
要捕获输出,请使用:
exec( 'abc.exe', &$output);
echo $output;
Link to exec
执行链接
回答by morteza hosseini
You can use VaccinalBowl code in windows, but for address .exe file, see the following example :
您可以在 windows 中使用 VaccinalBowl 代码,但对于地址 .exe 文件,请参见以下示例:
$answer = shell_exec("D://Downloads/software/npp.6.7.9.2.Installer.exe");
echo $answer."</br>";
回答by LinconFive
Encountered with permission problem even with 2&>1 (although chmod 777), but workaround by reading the output via saving into a file
即使使用 2&>1(尽管是 chmod 777)也遇到权限问题,但可以通过保存到文件中读取输出来解决
See the example, cs_crypto is something to decrypt
看例子,cs_crypto是解密的东西
<?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
所以最后的结果在 web
回答by ymk
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 中有一个“hack”,你可以在 Windows 中使用 Task Scheduler。以下代码适用于所有浏览器,而不仅仅是 IE。但是,我应该警告您,有时您正在访问的程序有时可能无法在那个瞬间运行,因为我有时注意到计划任务可能处于“排队”状态而不是运行。但是代码确实可以 100% 工作......这只是任务在任务调度程序中处于什么状态的问题......无论是“运行”还是“排队”。
<?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");
?>


