0

I have a jar file that writes something to stdout. I need to execute it from PHP and store what it writes.

public class Main{
    public static void main(String[] args) {
        System.out.println("Something...");
    }
}

Unfortunately the following script

<?php
    exec('java -jar Main.jar', $output);
    print_r($output);
?>

always shows that $output is an empty Array().

How do I force the output go to PHP?

0

1 Answer 1

3

Try this approach:

<?php
    exec('java -jar StringGenerator.jar $parameter 2>&1', $output);
    header("Location: /someURL/$output[0]");
?>

2>&1ensures that the output goes to the PHP handler.

Sign up to request clarification or add additional context in comments.

1 Comment

@M.C. what does the parameter you pass in look like?

Your Answer

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