gnome-terminal - how to get the pass/fail status of the invoked command

316 views Asked by At

I'm running a command inside a gnome-terminal like this:

gnome-terminal --disable-factory -x bash -c "<some_command>"

if i then check the pass/fail status of the last command using $? i always get 0, even if <some_command> fails.

Is there a way to reflect the pass/fail status of <some_command> to the original shell so $? will show the correct result?

1

There are 1 answers

2
cat On

This is not really possible because even with appending exit $? to the command, bash is a subprocess of gnome-terminal which is a subprocess of your shell session.

Even if gnome-terminal's subprocess (bash) exits abnormally, gnome-terminal's GTK+ UI process still exits normally with 0.

This sounds like an X/Y Problem -- rather than using gnome-terminal and checking the exit status, which is weird and convoluted, find the root of the problem you want to solve and chase that instead.