Open a new prompt/terminal window from Java

前端 未结 4 956
独厮守ぢ
独厮守ぢ 2020-11-27 21:30

I want to open a new terminal window, which will run a certain command upon opening. It preferably needs to be a real native window, and I don\'t mind writing different code

4条回答
  •  独厮守ぢ
    2020-11-27 22:21

    I've used this on Ubuntu(X11 Desktop) 10.04 ~ 14.04, and other Debian distro's. Works fine; although, you may consider using Java's ProcessBuilder.

         // GNU/Linux -- example
    
    Runtime.getRuntime().exec("/usr/bin/x-terminal-emulator --disable-factory -e cat README.txt");
    
     //  --disable-factory    Do not register with the activation nameserver, do not re-use an active terminal
    //    -e                  Execute the argument to this option inside the terminal.
    

提交回复
热议问题