开发者

How to run and kill processes in Fedora from a Java GUI

I'm working in Fedora. I want to create a GUI in Java with two buttons: START and STOP. I have two processes: p1 and p2. When I click on START, p1 should run in the background and p2 sh开发者_如何学Goould run in the foreground. (In the terminal, we do this by giving ./p1 and ./p2.) When I click on STOP, both the processes should be killed. (The terminal equivalent is: CTRL+C and kill -9 pid).

Can anyone suggest the way to do this?


As pointed out in the comments, in java you can use the Process and ProcessBuilder API's to start other processes.

The following links point to relevant API documentation: http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Process.html http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/ProcessBuilder.html

According to the API docs, you can start processes, pass command line arguments and environment variables to them, access their input and output streams and kill them.

There are also several related questions here on Stack Overflow that may be able to help e.g. this one.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜