Я пытаюсь запустить команду оболочки в linux через java. большинство команд работают, но когда я запускаю следующую команду я получаю execption, хотя она работает в оболочке:Почему следующий код не работает?
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);
}
я получаю сообщение об ошибке в консоли:
кошачьих:>: Нет такой файл или каталог
кошка: pic2.jpg: Нет такого файла или каталога
Я думаю, что это может быть связано - http://stackoverflow.com/questions/16238714/runtimes-exec-method-is-not-redirecting-the -вывод –