1

I am writing a PHP program and part of an XAMPP site that I have running on the localhost of my machine. I would like the file to input two of its strings into a Java program that I have saved on the desktop of my computer, and then store the output as a string. I have been trying to use shell_exec() but I have not gotten it to work.

Any tips?

    <?php
$artist = $_POST['artist'];
$songname = $_POST['songname'];

    $artist = preg_replace('/\s+/', '', $artist);
    $songname = preg_replace('/\s+/', '', $songname);

    $artist=strtolower($artist);
    $songname=strtolower($songname);

    echo $artist;
    echo $songname;

    $output = shell_exec("/Users/ianterry/Desktop/CussCalc2/java CussCalc '$artist' '$songname'");
    $output = shell_exec("/usr/bin/java -version");
    echo $output;
?>

So far, the only output I get when it is run is the two strings being echo'd.

4
  • 1
    you know $output is overriden by java version? Commented Dec 2, 2015 at 11:37
  • I did realize that. I put that in after testing the former to see if it would give any output; neither did. Commented Dec 2, 2015 at 11:49
  • I dont know much PHP but looking at the docs php.net/manual/en/function.shell-exec.php I see that "It is not possible to detect execution failures using this function. exec() should be used when access to the program exit code is required.". Maybe use the exec command instead and debug from there? Commented Dec 2, 2015 at 11:50
  • maybe use proc_open instead of shell_exec at least you will see what exactly is happening Commented Dec 2, 2015 at 13:19

1 Answer 1

0

At first you should check shell_exec and exec are allowed: PHP exec - check if enabled or disabled

Also, take a look at How to run Java program and get output in PHP?

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.