【发布时间】:2016-03-21 12:32:12
【问题描述】:
我正在尝试通过 java 在 linux 中运行 shell 命令。大多数命令都有效,但是当我运行以下命令时,我得到一个执行,尽管它在 shell 中有效:
String command = "cat b.jpg f1.zip > pic2.jpg";
String s = null;
try {
Process p = Runtime.getRuntime().exec(command);
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
System.out.println("Here is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
System.exit(0);
}
catch (IOException e) {
System.out.println("exception happened - here's what I know: ");
e.printStackTrace();
System.exit(-1);
}
我在控制台中收到错误:
cat: >: 没有这样的文件或目录
cat: pic2.jpg: 没有这样的文件或目录
【问题讨论】:
-
我认为这可能是相关的 - stackoverflow.com/questions/16238714/…