无法在PHP中使用exec()运行.exe文件 [英] Can't run .exe files using exec() in PHP

查看:367
本文介绍了无法在PHP中使用exec()运行.exe文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用.exe文件执行计算并将输出传递到PHP.我使用C ++制作了一个Hello World .exe文件,但无法使PHP执行该文件.

I'm trying to use an .exe file to perform calculations and pass the output into PHP. I made a Hello World .exe file using C++, but I can't get PHP to execute it.

如果我从CMD运行此命令,则会得到正确的输出:

If I run this command from the CMD, I get the correct output:

C:\path\file.exe

但是,如果我在PHP中执行此操作,则输出为空字符串:

But if I do this in PHP, the output is an empty string:

exec('C:\path\file.exe',$out);
var_dump($out);

但这将显示正确的输出:

But this displays the correct output:

exec('ipconfig',$out);
var_dump($out);

我在Windows 7上使用WAMP.

I'm using WAMP on Windows 7.

这是C ++程序:

#include <iostream>
using namespace std;

int main() {
    cout << "Hello World" << endl;
    return 0;
}

推荐答案

一些建议可能会有所帮助:

Few advices that may help:

  1. 改为使用/,它也可以在Windows下使用.
  2. 如果您的路径包含空格,请将其用双引号引起来$exec = '"C:/my path/file.exe"';
  3. 参数应在双引号$exec = '"C:/my path/file.exe" /help';之外传递
  4. 确保您的程序实际上是写入STDOUT而不是STDERR.
  1. Use / instead, it also work under windows.
  2. If your path contain spaces, wrap it in double quotes $exec = '"C:/my path/file.exe"';
  3. Parameters should be passed outside double quotes $exec = '"C:/my path/file.exe" /help';
  4. Make sure that your program actually writes to STDOUT, not STDERR.

这篇关于无法在PHP中使用exec()运行.exe文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆