There are several terminal emulators on Linux that allow you to interact with various shells . Each shell is basically a command interpreter that understands Linux commands (GNU and Unix commands are more correct, I suppose ...). The terminal emulator provides an interface (window) for the shell and some other features for using the command line. To open a terminal window, you just need to change your command line as follows: -
import java.io.*; class TerminalLauncher { public static void main(String args[]) throws IOException { String command= "/usr/bin/xterm"; Runtime rt = Runtime.getRuntime(); Process pr = rt.exec(command); } }
The main assumption I made is that you want to open xterm , which is available for almost any system (with X installed, of course). You might want to open another terminal emulator, such as rxvt, eterm, aterm, gnome-terminal or the console. The command line can also be modified to use different shells such as zsh . I suggest you catch an exception if the terminal you have selected is missing and processes it, asking the user to install it. The best solution is to accept command line arguments for your preferred user shell or use a configuration file that the user can modify so that your script opens the shell of his choice.
Note
1. As others have already indicated, xterm (or any other terminal of your choice) may not be specified in the specified path (/ usr / bin / ...) and may not even be installed, so you may have to use some ( Ex: pipelined navigation through grep to get the path to xterm before starting), which is not such a great idea. I think the best way is to let the user customize all this.
2.I received a comment on this answer (by ypnos), suggesting that I avoid using absolute paths and rather rely on the command found in the PATH environment variable. I have to say, I agree. In this case, the command line should be -
String command = "xterm"
Look at the comment because it also indicates a problem with find.
batbrat
source share