[英]exec() php always returning array (size=0) empty?
I'm trying to execute jar file in my php program. 我正在尝试在我的php程序中执行jar文件。 I'm testing with this simple example :
我正在用这个简单的例子进行测试:
exec('java -jar "C:\wamp\www\Hello.jar" myName', $output);
var_dump($output);
but it always printing 但它总是打印
array (size=0)
empty
BTW the jar file does System.out.println("hello "+args[0]);
顺便说一句,jar文件执行
System.out.println("hello "+args[0]);
and I'm testing it in cmd and it is working fine. 我正在cmd中对其进行测试,并且工作正常。
Please help I'm struggling with this problem since two days. 自两天以来,请帮助我解决这个问题。
try this: 尝试这个:
exec('java -jar \"C:\wamp\www\Hello.jar" myName', $output);
instead of 代替
exec('java -jar "C:\wamp\www\Hello.jar" myName', $output);
尝试
exec("/path_to_java -jar C:\wamp\www\Hello.jar myName", $output);
\\
with \\\\
\\\\
替换\\
2>&1
to display errors in output. 2>&1
将错误重定向到输出以显示输出中的错误。 Simple: 简单:
$JAR = 'C:\\wamp\\www\\Hello.jar';
$CMD = sprintf(
'java -Xmx32m -jar %s myName 2>&1'
,escapeshellarg($JAR)
);
exec($CMD, $Output, $Status);
var_dump($CMD, $Output, $Status);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.