简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM