问题描述
我正在用 java picocli 构建一个命令行应用程序,它基本上包含了 npm、maven、git、azure 和一些我想要预先完成的实用程序命令。我的问题是,例如,当运行 npm install 时,它会打印一系列内容,例如关于它安装的所有内容和日志的警告,以及写入大量内容的进度条。有什么方法可以将其模拟到我的应用程序中吗?现在我有这个来运行一个进程:
protected static void run(String dir,String... strings) {
try {
var process = new ProcessBuilder(strings).directory(new File(dir)).start();
process.waitFor();
write(process.getInputStream(),System.out);
} catch (IOException | InterruptedException e) {
e.printstacktrace();
}
}
private static void write(InputStream stream,PrintStream out) throws IOException {
String line = null;
StringBuffer buffer = new StringBuffer();
var reader = new BufferedReader(new InputStreamReader(stream));
while ((line = reader.readLine()) != null)
buffer.append(line);
out.println(buffer.toString());
}
有什么办法可以获得其他打印件和进度条吗?现在我只得到最后的 5 行,表示安装后的漏洞数量?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)