How to open a command terminal in Linux?

后端 未结 8 2121
情歌与酒
情歌与酒 2020-11-30 09:45

I want to open the terminal (command prompt) on a Linux machine using Java code. I know how to open command prompt in windows.The following code i have used in windows

相关标签:
8条回答
  • 2020-11-30 10:02

    There's no single standard "terminal" command on Linux - the ones available depend on which GUI is present (i.e. whether KDE, or Gnome, etc).

    You should be able to rely on xterm being present, but on modern Linux variants that's not the terminal of choice:

    String command= "/usr/bin/xterm";
    Runtime rt = Runtime.getRuntime();
    Process pr = rt.exec(command);
    

    Of course, "xterm" might not be in that particular path...

    0 讨论(0)
  • 2020-11-30 10:16

    There isn't actually a "the" terminal. What you really want is shell. Most Linuxes uses BaSH as a shell, but to keep on the safe side you should restrict yourself to /bin/sh

    Edit: Hmm I probably missunderstood the question. If you want an interactive terminal you should look into using a toolkit providing a component for that.

    Edit2: Maybe your needs can be served by VTE which is a GTK+ component for embedding a terminal.

    0 讨论(0)
提交回复
热议问题