Can't Stop Simultaneous Step Execution in Shell Script – xfce4-terminal command

#!/bin/sh
xfce4-terminal
zenity --info
exit

Expected behavior on my Xfce4 desktop when the script is run (via a keyboard shortcut) is that the Terminal window appears. Only when I close same should the Zenity window then appear.

Normally, this is exactly what happens. However, if I first open an Xfce4 Terminal window on the desktop, then command the subject script (again, via a keyboard shortcut), another terminal window appears (as expected), but, simultaneously, so does the Zenity window. This is undesired behavior.

I have tried many things, including the wait command and appending the terminal line with &&. Nothing is working for me.

What is causing this to happen and how can I remedy it?

Asked By: Digger

||

Give a try to this, I tested and looks good.

xfce4-terminal -x bash -c 'trap "zenity --info" EXIT; bash'

When executed, it opens a new xfce4-terminal, and executes the command following. This command is a shell trap. That means when this same process, the new-opened terminal, gets the signal to EXIT, will execute the quoted command. The last bash is to give a prompt, after the trap is set, like in this post. I also tried -H but didn’t work as expected.

Answered By: thanasisp

This https://bugzilla.xfce.org/show_bug.cgi?id=14544
And this 10 years earlier https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=434863

Suggests: xfce4-terminal --disable-server -e "command args ..."

And seems to work with no adverse effects that I notice.

It also works without the -e option. My own usage and the usage in the old bug reports needed -e so they only talk about "the effect it has on -e", but the OPs usage doesn’t involve -e, and the option does also cause a plain new terminal itself to block, not just a command specified by -e.

Apparently what happens (without the flag) is it doesn’t directly produce a terminal, it merely acts as a client that submits a request to a server to have the server produce a terminal. It exits instantly because all it does is send a tiny message, and the actual terminal is some other unrelated process that happens elsewhere.

The server and client are the same binary, merely if there is no server running already, then one is started and then used, and lives as long as there are any open terminal windows.

But in all cases, whether the first invocation or not, the initiating process exits immediately.

This is not necessarily a terrible scheme if it didn’t break every expectation and interoperability with every other program that wants to use a terminal app.

The older bug report was about an app which expected to be able to create a temp file, launch a text editor in a terminal to edit that temp file, block until the terminal exits, then pick up the temp file and do something with it after the user has edited it. And that worked for everything else in the world but broke with xfce4-terminal, yet the xfce4 dev only said the user was wrong a dozen times.

The –disable-server option seems to resolve it, but even there they seem to try to go out of their way to avoid saying what it actually does in any useful way. The option already existed when that user hit this problem, and the description in no way communicated that it was the way to get their desired behavior.

xfce4-terminal –help merely shows that the option exists, not what it does.
"man xfce4-terminal" only says (still today):

--disable-server
           Do not register with the D-BUS session message bus

What?

Answered By: Brian White
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.