我正在运行使用Java的命令并且没有输出。使用Java运行Linux命令时出现问题?
Process p;
Runtime run = Runtime.getRuntime();
String s1 = "queryData 1005017 --format '\"%s" scope'";
System.out.println("Command is " + s1);
try {
p = run.exec(s1);
BufferedReader br = new BufferedReader(
new InputStreamReader(p.getInputStream()));
while ((s = br.readLine()) != null)
System.out.println("line: " + s);
p.getErrorStream();
p.waitFor();
}
while the command ---> queryData 1005017 --format''%s“scope'runs without any issue。想知道是否在处理双引号或%符号时丢失了任何内容?
假设你丢失的反斜杠只是一个错字(?没有你的程序编译),你尝试过检查'p.exitValue()'了'waitFor'后,看它是否终止成功或没有? – RealSkeptic
是的,这是错字。我得到的退出值是退出:1 – Ammad
因此退出失败。尝试阅读错误流而不是输入流,看看它给你带来了什么样的错误。 – RealSkeptic