gpt4 book ai didi

java - 为什么下面的代码不起作用?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:57:00 26 4
gpt4 key购买 nike

<分区>

我正在尝试通过 java 在 linux 中运行 shell 命令。大多数命令都有效,但是当我运行以下命令时,我得到了一个 execption,尽管它在 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: 没有那个文件或目录

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com