I am working in java for Ubuntu environment. I want to execute a script file but through java program. I have tried followings
try{
Runtime.getRuntime().exec("/usr/lib/flume-ng/bin/flume-ng agent -f /home/c4/Flume/New/ClientAgent.config -n clientAgent");
}
catch(Exception e){
e.printStackTrace();
}
And
ProcessBuilder pb = new ProcessBuilder("/usr/lib/flume-ng/bin/flume-ng", "agent",
"-f", "/home/c4/Flume/New/ClientAgent.config","-n","clientAgent");
try{
pb.start();
}
catch(Exception e){
e.printStackTrace();
}
But both of these don't start my process named: flume-ng, other are parameters passed to it. Java program compiles successfully but neither gives exception etc nor run process. Please guide me if i am doing something wrong.
Consider Apache Commons Exec
It provides reliable and cross-platform mechanism to launch external processes.
Here is the latest javadoc: http://commons.apache.org/proper/commons-exec/apidocs/index.html
And here is the simple tutorial: http://commons.apache.org/proper/commons-exec/tutorial.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.