更新时间:2022-11-26 12:22:45
您正在传递的参数不正确尝试下面code:
过程PROC =调用Runtime.getRuntime()。EXEC(/无功/网络/ redbutton / marsh_webreset.sh+阵列[0] ++阵列[1] + /);
I am trying to run a bash script on my Ubuntu machine through Java. The bash script takes 2 input as parameters that i am passing as an array However, it does not seem to be passing the value of array[0] and array[1] to the bash script ?
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.omg.CORBA.portable.InputStream;
public class readBashScript {
public static void readBashScript() {
try {
String[] array = {"ys1","R"};
Process proc = Runtime.getRuntime().exec("var/www/red/marsh_webreset.sh /",array);
BufferedReader read = new BufferedReader(new InputStreamReader(
proc.getInputStream()));
try {
proc.waitFor();
} catch (InterruptedException e) {
System.out.println(e.getMessage());
}
while (read.ready()) {
System.out.println(read.readLine());
}
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
You are passing the arguments incorrectly Try below code:
Process proc = Runtime.getRuntime().exec("/var/www/redbutton/marsh_webreset.sh "+array[0]+" "+ array[1]+" /");