运行显示输出/解析命令的 .jar 文件

发布于 2024-11-27 11:41:20 字数 588 浏览 0 评论 0原文

我想要运行一个 .jar 文件并显示输出(我假设我会使用富文本框),但是我也想要一个文本框,它允许我将命令发送到正在运行的 jar 文件,就好像它一样在命令提示符窗口中运行。

无论是这样做还是嵌入命令提示符都是理想的选择。我把代码弄乱了,但从来没有让它工作过。

我还想检测 jar 文件返回的某些消息,例如,如果运行某个命令,它将显示一条消息,具体取决于该命令是否失败,是否有一种方法可以读取返回的所有内容,然后发生一个事件如果它检测到这个特定的字符串会发生什么?

如何:在 C# 中执行命令行,获取STD OUT 结果 我一直在研究诸如此类的事情,当我说我搞乱了代码时,我已经尝试过这些示例中给出的代码(更改小部分),但它们从未起作用。

总结一下: - 我想运行一个 jar 文件,该文件在命令提示符中明显显示其输出。 - 我想隐藏命令提示符并在富文本框中显示其输出。 - jar 文件将返回诸如“用户 1 已登录”之类的字符串,我想每次发生这种情况时都更新标签文本。

I am wanting to run a .jar file and display the output (I'm assuming I would use a rich text box) however I also want to have a text box that will allow me to send commands to the running jar file as if it were running in a command prompt window.

Either this or embedding the command prompt would be ideal. I have messed around with code and have never got it to work.

I would also like to detect certain messages that the jar file returns, for example if a certain command is ran it will display a message depending on whether or not that failed, is there a way to read everything that get returned and then have an event happen if it detects this certain string?

How To: Execute command line in C#, get STD OUT results I have been looking at things such as that, when I say I have messed around with code, I have tried the code given in these examples (changing small parts) they never worked.

To summarise:
- I want to run a jar file that obviously displays it's output in a command prompt.
- I want to hide the command prompt and display it's output in a rich text box.
- The jar file will return string such as 'user 1 has logged in' I want to update a labels text everytime that happens.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉梦枕江山 2024-12-04 11:41:20

您应该查看 ProcessBuilder 和 Process 类。它们允许运行命令行程序并在进程流中读/写。

另外,如果您的 jar 是预先知道的,为什么不简单地使用该类,就好像它在库中一样并使用公开的 API?

You should have a look at the ProcessBuilder and Process classes. They allow to run command line programs and read/write in the process streams.

Also, if your jar is known in advance, why no simply using the class as if it would be in a library and use the exposed APIs?

七度光 2024-12-04 11:41:20

当我们在学校开始学习 java 时,我们使用

String myInput = JOptionPane.showInputDialog(this, "myPrompt");

and

JOptionPane.showMessageDialog(null, "A basic JOptionPane message dialog");

来进行输入和输出。很简单。

或者您可以使用命令行:

BufferedReader br = new BufferedReader(new InputStreamReader(System.in)
String input = br.readLine();

When we started learning java at school we used

String myInput = JOptionPane.showInputDialog(this, "myPrompt");

and

JOptionPane.showMessageDialog(null, "A basic JOptionPane message dialog");

for input and output. Very simple.

Or you can use the command-line:

BufferedReader br = new BufferedReader(new InputStreamReader(System.in)
String input = br.readLine();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文