Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get default terminal application on linux system using Java

I am looking for a way to find out which one of these xterm, konsole, aterm, gnome-terminal terminal applications are present on Linux distro or a default one at runtime within a java program.

It is required to execute certain commands from my java program and so need to know which terminal to use or at least if it is present and can be used.

xterm can be used by default but would be good to know if there is something more advanced available to use. Even there is no guarantee if xterm is installed either.

like image 828
Indigo Avatar asked Jul 21 '26 13:07

Indigo


1 Answers

If you want full portability and a "native terminal emulator", you will have to code something that picks the "right" terminal emulator yourself. There are two commands that do a bit of choosing themselves:

  • On Debian based Distro's you can use x-terminal-emulator -e <cmd>, however this does not work on e.g. Centos.
  • FreeDesktop has xdg-terminal (code) as part of the xdg-utils package, however the script seems not to be distributed at all.

Since neither of these is guaranteed to be present, you will still have to test for availability and use xterm etc. as fall-back.

like image 98
Elmar Avatar answered Jul 24 '26 03:07

Elmar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!