我开发了一个能够在Ubuntu中运行Linux命令的java程序,但是当我在rhel中尝试相同的程序时,我的代码无法正常工作,我的代码无法执行Linux命令,但如果我直接执行了通过终端命令,它能够显示输出
这是我的示例程序
与UTRntu有什么不同吗?我检查了我的bash文件rhel在/usr/bin
文件夹下
String temp1 = "'/" + t1 + "/,/" + t2 + "/p'";
String command2 = "sed -n " + temp1 + "\t" + confstr2;
System.out.println( "The command2 is : " + command2 );
ProcessBuilder pb1 =
new ProcessBuilder(
"/usr/bin/bash",
"-c",
command2
).directory( new File( confstr3 ) );
Process p2 = pb1.start();
BufferedReader br2 = new BufferedReader( new InputStreamReader( p2.getInputStream() ) );
String line2;
File file1 = new File(confstr4);
if(file1.createNewFile()) {
System.out.println("File is created!");
}
else {
System.out.println("File already exists.");
}