How to propagate an error code outside a terminal?

philipper

From inside a bash script I try to retrieve the error code of a program launched in a new terminal window. It can be reduced to this:

#!/bin/bash
urxvt -e bash -c "exit 4"
echo $?

output: 0

I would like to access the "4" in my script that is calling urxvt. How can I do that please? :)

Parsa Mousavi

AFAIK graphical terminals such as uxvrt doesn't have any utility to give you the return code of the program you've run on them.

The best and most straightforward way that came into my mind is to run a sub-shell inside your bash ( looks a little cluttered , but trust me ) and run whatever program you want inside the inner bash and use the outer one to handle the return code as follows :

urxvt -e bash -c ' (exit 4) ; echo $? > error.code '

Now you can read the return code from the file error.code.

Note that the existence of a temporary file is necessary since if you just echo the return code , it gets printed in the urxvt window which itself will get closed after a few thousands of the second.So you wouldn't get anything useful.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to propagate nested error in Q .then() callback

From Dev

How to run script outside of terminal with admin priviliges?

From Dev

How to propagate a promise error to a higher promise level after loading a file?

From Dev

Error in terminal while running a code

From Dev

How to propagate (or introspect) nargout?

From Dev

How to propagate the value of a variable

From Dev

How to propagate between aspects

From Dev

Can't propagate exit code

From Dev

How to print to the terminal in this Haskell code?

From Dev

Propagate error string: Fortran > C

From Dev

BASH get error code in parent terminal from child terminal?

From Dev

How to propagate error when using scipy quad on a spline of data with measurement error?

From Dev

PHP & XML: How to remove all whitespaces outside "terminal elements"

From Dev

PHP & XML: How to remove all whitespaces outside "terminal elements"

From Dev

Terminal and Grepping Stderr: how do I run a verbose code and grep the standard error without changing anything else?

From Dev

How to call python code from outside of Python

From Dev

How to make an error propagate out of EXEC and abort the rest of the script in T-SQL?

From Dev

Protractor: How should I propagate an error from within browser.executeAsync?

From Dev

How does floating point error propagate when doing mathematical operations in C++?

From Dev

Protractor: How should I propagate an error from within browser.executeAsync?

From Dev

How to propagate a commit to child branches?

From Dev

How propagate HTMLAttributes to a custom EditorTemplate?

From Dev

Add a row to a matrix inside a function (and propagate the changes outside) in Julia?

From Dev

Why does mutating a passed Option inside a function not propagate to the Option outside?

From Dev

Geany - How to execute code in terminal pane instead of external terminal

From Dev

How to show an error outside of a form in Rails

From Dev

how to fix "Index was outside the bounds of the array" Error

From Dev

Parted: how to solve Location outside of device error?

From Dev

Propagate Schema and Code Changes Across Multiple Databases

Related Related

  1. 1

    How to propagate nested error in Q .then() callback

  2. 2

    How to run script outside of terminal with admin priviliges?

  3. 3

    How to propagate a promise error to a higher promise level after loading a file?

  4. 4

    Error in terminal while running a code

  5. 5

    How to propagate (or introspect) nargout?

  6. 6

    How to propagate the value of a variable

  7. 7

    How to propagate between aspects

  8. 8

    Can't propagate exit code

  9. 9

    How to print to the terminal in this Haskell code?

  10. 10

    Propagate error string: Fortran > C

  11. 11

    BASH get error code in parent terminal from child terminal?

  12. 12

    How to propagate error when using scipy quad on a spline of data with measurement error?

  13. 13

    PHP & XML: How to remove all whitespaces outside "terminal elements"

  14. 14

    PHP & XML: How to remove all whitespaces outside "terminal elements"

  15. 15

    Terminal and Grepping Stderr: how do I run a verbose code and grep the standard error without changing anything else?

  16. 16

    How to call python code from outside of Python

  17. 17

    How to make an error propagate out of EXEC and abort the rest of the script in T-SQL?

  18. 18

    Protractor: How should I propagate an error from within browser.executeAsync?

  19. 19

    How does floating point error propagate when doing mathematical operations in C++?

  20. 20

    Protractor: How should I propagate an error from within browser.executeAsync?

  21. 21

    How to propagate a commit to child branches?

  22. 22

    How propagate HTMLAttributes to a custom EditorTemplate?

  23. 23

    Add a row to a matrix inside a function (and propagate the changes outside) in Julia?

  24. 24

    Why does mutating a passed Option inside a function not propagate to the Option outside?

  25. 25

    Geany - How to execute code in terminal pane instead of external terminal

  26. 26

    How to show an error outside of a form in Rails

  27. 27

    how to fix "Index was outside the bounds of the array" Error

  28. 28

    Parted: how to solve Location outside of device error?

  29. 29

    Propagate Schema and Code Changes Across Multiple Databases

HotTag

Archive