44

I have tried to use exec() with 'whoami' to check if it works and I got the result of

nt authority\system

Now I need to run a .exe file with parameters from php via exec() function.

I tried this in command prompt and it actually runs the program with given parameters. This is the example command.


NOTE the exe file gets 3 inputs (folder, file_name, report_file_nmae)

> ..\..\some_file.exe folder="C:\path_to_folder" param=1.xml report=2.xml

But when I run this command from php file:

exec('..\..\some_file.exe folder="C:\path_to_folder" param=1.xml report=2.xml');

nothing is happening. This is the first time I am using exec() function, so I am not familiar with its details. What is wrong?

I tried using:

  • \\ instead of \
  • escapeshellarg() on the directory
  • added "" around directory folder names

No luck

Addendum:

echo exec($command)  // echos < .... why?

or

exec($command, $output);
print_r($output);        // Array()

I even changed the permission on the file to full control to all users. If I call the program from command prompt, I can see the icon appearing next to clock for a second.

But the same call from php will not even call the program.

Edit

Even exec('notepad.exe'); is not working. Something has to be done with php configurations maybe?

4

2 回答 2

108

我已经说过我是新手exec()。在进行了更多挖掘之后,我发现2>&1需要在exec().

也感谢您@mattosmat在评论中指出这一点。我没有立即尝试这个,因为你说这是一个 Linux 命令,我在 Windows 上。

所以,我发现,该命令实际上是在后端执行的。这就是为什么我看不到它实际运行的原因,这是我所期望的。

对于遇到类似问题的所有人,我的建议是使用该命令。它会指出所有错误并告诉您有关执行的信息/详细信息。

exec('some_command 2>&1', $output);
print_r($output);  // to see the response to your command

感谢所有帮助家伙,我很感激;)

于 2013-07-29T16:55:36.597 回答
0

您也可以尝试提供您尝试运行的二进制文件的完整路径。这解决了我在尝试使用时遇到的问题ImageMagick

于 2016-01-29T15:49:51.240 回答