通过java在linux终端上执行命令
我创建了一个独立的应用程序,我希望当用户单击运行按钮时,终端应该打开,并且应该在终端上执行特定的命令。我可以使用以下代码成功打开终端...
Process process = null;
try {
process = new ProcessBuilder("xterm").start();
} catch (IOException ex) {
System.err.println(ex);
}
上面的代码打开一个终端窗口,但我无法在其上执行任何命令。谁能告诉我该怎么做?
I have created an standalone application in which i want that when the user clicks on the run button then the terminal should open and a particular command should be executed on the terminal. I am able to open the terminal successfully using the following code...
Process process = null;
try {
process = new ProcessBuilder("xterm").start();
} catch (IOException ex) {
System.err.println(ex);
}
The above code opens a terminal window but I am not able to execute any command on it. Can anyone tell me how to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试
Try
按原样执行 linux 中的任何命令,就像您在终端中键入的内容一样:
用法:
或复杂为:
Execute any command in linux as is,as what you type in the terminal:
Usage:
or as complex as:
假设您正在尝试 gedit 命令,那么您需要提供 gedit 的完整限定路径(例如 /usr/bin/gedit)。同样,对于所有其他命令指定完整路径。
Suppose you are trying your gedit command then you need to provide the full qualified path to gedit (e.g /usr/bin/gedit). Similarly for all other command specify the full path.