Windows上的PHP exec Java不会产生任何输出

clo*_*jas 2 php exec

我已经阅读了很多关于我的问题的类似SO问题,似乎没有一个问题.如果它是相关的,我在Apache 2.2上运行PHP 5.3.8并且PHP运行的exec()nt authority\system

$cmd = "java -version";
$res = exec($cmd, $output, $return);

var_dump($res, $output, $return);
Run Code Online (Sandbox Code Playgroud)

生产:

string '' (length=0)

array
    empty

int 0
Run Code Online (Sandbox Code Playgroud)

$return0提示这是成功的.有趣的是,如果我跑:

$cmd = "java -version 2> response";
Run Code Online (Sandbox Code Playgroud)

使用预期输出创建文件:

java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)
Run Code Online (Sandbox Code Playgroud)

所以我的问题:为什么$output没有人口稠密?

评论更新

的结果 $res = exec("dir c:", $output, $return);

string '               2 Dir(s)  335,636,791,296 bytes free' (length=51)

array
    0 => string ' Volume in drive C is Local Disk' (length=32)
    1 => string ' Volume Serial Number is D87C-E25C' (length=34)
    2 => string '' (length=0)
    ...
    12 => string '               5 File(s)          1,158 bytes' (length=45)
    13 => string '               2 Dir(s)  335,636,791,296 bytes free' (length=51)

int 0
Run Code Online (Sandbox Code Playgroud)

Haw*_*ili 8

试试这个

$output = `java -version 2>&1`
Run Code Online (Sandbox Code Playgroud)

注意命令周围的反引号,它完全像shell命令一样

2>&1应该将错误重定向到stdout,因为java默认使用stderror!