It seems that 'exec' can only be used with files containing commands (& not the commands themselves) e.g. .exe or .bin, etc. The compiler gave as output 'System.out.println(5) not found.'. An IOException is thrown.
2/ Compiler.command("System.out.println(5);");
No output at all.
3/ Methods like 'runWithCommand' or 'Execute' do not seem to work.
One may wonder why I don't write the command directly. It's just that the commands are in the form of a string from, let's say a database, & I need to run these commands. Note that other programming software does allow the programmer to do this.
I don't know if there exists something like that, but this term should help you search for it.
Runtime.exec() calls external programs (see API), not Java Methods. The Compiler class has nothing to do with your problem (as I understood reading the API documentation).