我正在尝试通过Java在我的Ubuntu机器上运行一个bash脚本。该bash脚本需要2个输入参数,我将它们作为数组传递。然而,似乎没有将array[0]和array[1]的值传递给bash脚本?
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());
}
}
}
ProcessBuilder
,尽管在shellshock事件中,这似乎是一段非常危险的代码。 - Elliott Frisch