gpt4 book ai didi

java - runtime.exec() 花费无限时间来执行代码

转载 作者:行者123 更新时间:2023-11-29 18:36:16 26 4
gpt4 key购买 nike

我想执行一个带有 2 个参数的命令。1.输入文件名2.输出文件名。

命令为 SixV1.1 outputFile.txt代码是:

   String cmd= "sixV1.1 <inputFile.txt >outputFile.txt";
Process p=Runtime.getRuntime().exec(cmd);
int retValue=p.waitFor();

当我运行上面的代码时,它花费了无限的时间。是否可以在 cmd 中给出 <, > 字符。请建议我....

最佳答案

在 Java 中启动进程时进行输入/输出重定向的正确方法是从进程的流中写入/读取:

Process p = Runtime.getRuntime().exec("sixV1.1");
InputStream is = p.getInputStream();
// read from is and write to outputFile.txt
OutputStream os = p.getOutputStream();
// read from inputFile.txt and write to os

关于java - runtime.exec() 花费无限时间来执行代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45264978/

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