0

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 :)

1
  • what about stderr? Try appending 2> C:\\stderr.txt to your command, run it again and see if there is something in C:\\stderr.txt Commented Jan 25, 2013 at 9:22

1 Answer 1

1

i searched an found the answer like this:

  1. java treat java.exe execution as a normal output when javac.exe as an error. this make the first code returns output but not with the second.
  2. the third code seems (un)like the first. yes it executes the java.exe, but with an aditional option -version. and java treat the output as an error. i have no idea why do they treat them differently.

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);
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.