Php shell_exec executing java program

In PHP code, I try to execute a Java program using shell_exec, but I get an empty string.

When I tried to execute the program in bash:

#bin/bash

echo "aaa"

I get "aaa", but when I tried to execute the same file with

#bin/bash

java MainApp

I have an empty string

This is java code

public class MainApp{
        public static void main(String[] args)
        {
                System.out.print(":]");
        }
}

When i do:

#bin/bash

echo "aaa"
java MainApp
echo "bbb"

I get "aaa bbb"

I can’t get the line ::] How to make it work?

Is it possible that the print line with System.out.println (String) does not match the print echo line, does not match the return value

+3
source share
1 answer

Shell_exec () php command not working for my custom java application

There was the same problem:]

I used

echo shell_exec ( "/usr/bin/java MainApp" );

:] , bash "java", :]

+2

Source: https://habr.com/ru/post/1749599/


All Articles