0
I need to run a Java program that is on my server, for example Teste.java
and return the console output resulting from the execution, either an error, or a phrase like Olá Mundo!
, using PHP.
I’ve used commands like exec("java Teste", $output)
and system("java Teste", $output)
, and could actually run the program, but could never return the console output that this program generated.
Is there any way to do the execution of this program, and return the output of it?
With the command
system("java Teste", $output)
it is possible to display in the console the return of your java code. It tries to run ajava Teste
right on the console to check if it returns an error. You compiled your class ??– Oliveira
After doing what @Oliveira suggested, try. exec("java Test", $output) var_dump($output);
– Marcos Xavier
@Oliveira, yes I compiled my class, via
system("javac C:\Users\Desktop\Hello.java", $saida);
, I also compiled via console just to make sure. But when I try to run code withsystem("java C:\Users\Desktop\Hello", $saida);
, and print the output variable, only the number is printed1
– user42676
@Marcosxavier also used the
exec()
, but I was unsuccessful :(– user42676
@Gamen probably had not compiled its class when running 'system("java C: Users Desktop Hello", $output);' the return was the value 1, if the class had been compiled it would display the value 0.
– Oliveira