Terminal Emulator – Most Portable Method of Launching a Terminal Emulator

portabilityterminal-emulator

Say I need to write a script that will launch a terminal and execute a command and I need that to work on various systems. How can I do that in a safe and portable manner?

Is xterm always installed? I assume that any *nix with a GUI must have some terminal emulator. How can I get to it? Debian systems have x-terminal-emulator but that, apparently, does not even work in Red Hat, let alone non-Linux *nixes.

Best Answer

I don't think you can. xterm need not be installed everywhere, and indeed probably isn't by default. Especially when a desktop environment is in use that provides its own terminal.

I think your best bet is probably to check for the existence of a few different terminals (say, xdg-terminal, x-terminal-emulator, gnome-terminal, konsole, xterm). And maybe work towards getting xdg-terminal actually added to the FreeDesktop.org standards.

Then you'll get to find that different terminals have different ways to run commands, and sometimes even different versions of the same terminal... e.g., see Debian Bug #648271.

You should probably also give the admin/user a way to set a custom command. It'll surely be needed.

Related Question