运行显示输出/解析命令的 .jar 文件
我想要运行一个 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该查看 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?
当我们在学校开始学习 java 时,我们使用
and
来进行输入和输出。很简单。
或者您可以使用命令行:
When we started learning java at school we used
and
for input and output. Very simple.
Or you can use the command-line: