我有一个Linux命令,在Java中无法执行:
[ ! -d "/tmp/flow" ] && echo "The directory DOES NOT exist."
它在命令行中运行良好,但是当我使用以下代码时:
String command = "[ ! -d \"/tmp/flow\" ] && echo \"The directory DOES NOT exist.\"";
Process proc = Runtime.getRuntime().exec(command);
Boolean successful = proc.waitFor()==0 && proc.exitValue()==0;
System.out.println("successful:"+successful);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
String line = null;
System.out.println("************** input");
while ((line = stdInput.readLine()) != null) {
System.out.println(line);
}
System.out.println("************** error");
while ((line = stdError.readLine()) != null) {
System.out.println(line);
}
它说:
successful:false
************** input
************** error
[: missing ']'
有任何想法吗?这些IF bash运算符无法从Java中调用,可能吗...?
谢谢!
**************** 更新 ****************
vikhor@adnlt653-vm1:~> which '['
[ is a shell builtin
[ is /usr/bin/[
[ is /bin/[