I want to make a java web interface that run bash process in the background. So, in java how can I run linux command like "ls -al" or run bash script. Is there any package or java plugin that able to invoke OS command in JAVA?
Thanks all
I want to make a java web interface that run bash process in the background. So, in java how can I run linux command like "ls -al" or run bash script. Is there any package or java plugin that able to invoke OS command in JAVA?
Thanks all
As I showed here: Compiling a C Source through javacode using gcc
You could use ProcessBuilder
to do that:
String directory = "/home/user";
String[] commands = {"ls", "-al"};
ProcessBuilder pb = new ProcessBuilder();
pb.directory(new File(directory));
pb.command(commands);
Process p = pb.start();
OuputStream out = p.getOutputStream(); // to send other commands/data
InputStream in = p.getInputStream(); // to read console response
// process the streams
As already shown here
You can use the Runtime.exec()
method.