I have this piece of code part of my desktop app that I am building using Rust+Tauri(A docker GUI client). I want to allow the user to click on the button and it should spwan a terminal app that basically runs the exec
command.
The Problem:
I have figured out how to do it for my system(running Linux/Pop!os) but how do I make it work on all the various linux distros (for now, cross-os support will be later). I know I have "gnome-terminal" app that I can hardcoded it & it is working.
let mut terminal_app: String = String::from("gnome-terminal"); // How do I get this dynamically?
let docker_command = format!("docker exec -it {} sh", container_name);
let mut command = std::process::Command::new(terminal_app);
let args = ["--", "bash", "-c", &docker_command];;
command.args(&args);
match command.spawn() {
Ok(_) => Ok("Exec command executed".to_string()),
Err(err) => Err(format!("Cannot run exec command: {}", err.to_string())),
}
I will be grateful for your help…
2
Answers
In you app settings ask for the name of the terminal and command line to execute and external command, probably using placeholders.
There’s also xdg-terminal-exec but not commonly installed.
Finally, you can also rely on environment vars like
TERMINAL
or something more specific for. your app.You can create a list of popular terminal emulators (like
gnome-terminal
,xterm
,konsole
,xfce4-terminal
, etc.) and check which one is installed on the system. This can be done using thewhich
command to see if the terminal is available in the user’s PATH, something like this