0

I have a Python terminal application, that I call from a .desktop file, something like this:

[Desktop Entry]
Version=1.0
Name=My App
Exec=python3 /home/pi/my_app.py
Terminal=true
Type=Application
Categories=Application;

And it does what I want: when I double-click the desktop shortcut, terminal starts up, application runs, when it is done, the terminal is shut down too.

However, recently I started getting some errors/exceptions which force the Python application to shut down - and as this also shuts down the terminal, I cannot read the error messages.

So I tried something like this:

[Desktop Entry]
Version=1.0
Name=My App
Exec=python3 /home/pi/my_app.py ; read -p "press"
Terminal=true
Type=Application
Categories=Application;

... however, since it is directly in the Exec argument, and there is no explicit call to bash, the read .. part is interpreted as command line arguments to the Python program, and now the program crashes instantly, shutting down the terminal (but at least it was easier to repeat this, and realize that the error message is from Python about command line arguments).

Note that I would prefer not to add a call to bash in the .desktop file, since I've noticed, when I run this app directly from a terminal, I cannot get the error reproduced (apparently the error somehow shows up only when I run it from double-clicking the .desktop file).

So, what else can I do, to run this application via the .desktop shortcut in a terminal, and have it not close the terminal window when the application exits, so I can read the error messages?

0
0

Gnome Terminal has an option to hold the terminal open when a command exits, shown below. Setting that should keep it open after a crash so you could see any error(s). Other terminals may have a similar option.

Screenshot showing option to hold the terminal open

If Gnome Terminal isn't you're default (and assuming you've installed it, if necessary), you can explicitly call it from a .desktop file to run your Python app:

[Desktop Entry]
Version=1.0
Name=My App
Exec=gnome-terminal --command 'python3 /home/pi/my_app.py'
Terminal=false
Type=Application
Categories=Application;

Note that the Terminal option is set to false because you're not wanting to run gnome-terminal in a terminal.

The exit behavior option is per profile, so you can create a profile (e.g. 'Hold Open'), just for situations where you want the terminal kept open on exit, and change the Exec option to something like the following to specify use of that profile:

Exec=gnome-terminal --profile='Hold Open' --command 'python3 /home/pi/my_app.py'

For some reason, Gnome Terminal's command line arguments aren't documented in its GUI-accessible help documentation. For a full list of these, run gnome-terminal --help-all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.