如何在php中运行exe文件

如何在php中运行exe文件,php,python,exe,Php,Python,Exe,我正在用python编写分类算法,它与php代码相关,为了得到正确的结果,我应该运行python exe,然后转到php代码 我想用php代码自己执行python。我试过这个: <?php // outputs the username that owns the running php/httpd process // (on a system with the "whoami" executable in the path) echo exec('whoami'); ?>

我正在用python编写分类算法,它与php代码相关,为了得到正确的结果,我应该运行python exe,然后转到php代码

我想用php代码自己执行python。我试过这个:

<?php
// outputs the username that owns the running php/httpd process
// (on a system with the "whoami" executable in the path)
echo exec('whoami');
?>

但它不起作用,我应该知道更多关于路径的信息吗?如何将我的exe文件放入写入路径?


<?php
exec("C:\\Users\\posh\\AppData\\Local\\Programs\\Python\\Python35\\python.exe YOUR_PYTHONSCRIPT.py <arguments if any>", $output, $ret_code);
// directly writing python may not work in that case 
// give path to python.exe
exec("python YOUR_PYTHONSCRIPT.py <arguments if any>", $output, $ret_code);
// $ret_code : returns the code 0 or 1
// output is an array
?>

你能详细说明“不工作”意味着什么吗?@castis什么都没有发生,直到我自己打开exe文件才有结果。对不起,回音线上方的评论解释了“不工作”的原因。。。我们没什么可以解释的了。。。尝试将“whoami”更改为实际的windows命令(“ipconfig”可能),因为它听起来像是您所在的操作系统……如果exe位于php执行的同一目录中,您可能只需将whoami更改为“some.exe”,请不要只是发布任意代码片段(尤其不是
exec()
calls…)。解释你在做什么以及为什么它解决了OP的问题,这样他们可以从经验中学习。