Reputation: 417
i am having a very unusual problem related to PHP shell_exec(). well, i am actually going to execute external java program. i make a test like this
<?php
$command = 'C:\\Program Files\\Java\\jdk1.6.0_35\\bin\\java.exe';
$val = shell_exec($command);
echo('command:' . $command);
echo('<BR>');
echo('val:' . $val);
?>
everything is OK, but when i am trying to do this
<?php
$command = 'C:\\Program Files\\Java\\jdk1.6.0_35\\bin\\javac.exe';
$val = shell_exec($command);
echo('command:' . $command);
echo('<BR>');
echo('val:' . $val);
?>
no output produced. really odd. i have also tried to use exec() but no different. the next odd thing is when i am try this one
<?php
$command = 'C:\\Program Files\\Java\\jdk1.6.0_35\\bin\\java.exe -version';
$val = shell_exec($command);
echo('command:' . $command);
echo('<BR>');
echo('val:' . $val);
?>
i use the exact java.exe but add a -version as an extra option. no output come up.
either java.exe and javac.exe give output when they are executed in the command line. i use Win 7 64bit, XAMPP 1.8.1 (Apache 2.4.3, PHP 5.4.7) and JDK 1.6 update 35.
i searched about this thing here, and tried to implement answer given to the related question, but they don't solve.
any explanation related to this,.? thank you for helping :)
Upvotes: 0
Views: 419
Reputation: 417
i searched an found the answer like this:
so the code would be okay if we put and extra 2>&1 which will redirect the standard error to standard output.
<?php
$command = '"C:\\Program Files\\Java\\jdk1.6.0_35\\bin\\javac.exe" 2>&1';
$val = shell_exec($command);
echo('command:' . $command);
echo('<BR>');
echo('val:' . $val);
?>
and so with this
<?php
$command = '"C:\\Program Files\\Java\\jdk1.6.0_35\\bin\\java.exe" -version 2>&1';
$val = shell_exec($command);
echo('command:' . $command);
echo('<BR>');
echo('val:' . $val);
?>
Upvotes: 1