gpt4 book ai didi

java - 如何在 Eclipse 插件中运行 .exe 并捕获输出。 ( java )

转载 作者:行者123 更新时间:2023-12-01 05:09:32 24 4
gpt4 key购买 nike

Possible Duplicate:
Capturing stdout when calling Runtime.exec

好的,

我正在开发一个 Eclipse 插件,它生成一些基于可视化界面的 PHP 代码(即用户在 View 上拖放一些内容,然后我的插件将使用关联的代码更新一些 php 文件)

我正在使用 FileUtils (Apache Commons) 创建 php 文件,并使用 ASTParser 生成 PHP 代码。

我的问题是我需要美化新生成的代码并进行良好的缩进。我用谷歌搜索了一下,发现了这个http://www.waterproof.fr/products/phpCodeBeautifier/ 。它以 .exe 文件形式出现。我已将其添加到资源中,但在调用它并从中获取输出时遇到一些问题。

我该怎么做?另外我不得不说我需要它在 Mac 和 Windows 机器上都能工作。这可以做到吗?有没有更简单的方法来美化代码?

谢谢!

最佳答案

如果您可以从命令行运行它并传递文件路径来美化代码,您可以使用以下代码来运行它并捕获结果。

Process p = Runtime.getRuntime().exec("executable.exec");

BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));

while ((String line = input.readLine()) != null) {
System.out.println(line);
}

另请参阅: How to capture the data returned from an EXE excuted from a batch?

How can i get the console output generated by a exe file?

Capturing stdout when calling Runtime.exec

关于java - 如何在 Eclipse 插件中运行 .exe 并捕获输出。 ( java ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12218138/

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