Return value from an app?


Is this possible to get the return value from a launched with a bash script? For instance below i always get the 0 value (while i use “setApplicationReturnValue” in my code).

open -W --args bar
echo "$?"

My assumption is that it is not possible without calling directly the binary (e.g. Is there any obvious trick that i’m not aware?

Thus, finally i communicate by writing and reading a text file.

I think that this is not supposed to work  at all with the open command:

if you do echo "$?", this will actually print the return value of the open command (where 0 probably means "opened successfully"), and not the return value of the app itself.

Yep, you are right. I realized it later, searching in StackOverflow archives.

(For future readers), consequently i use a log file.

# Read the result in the log file.

result=$(tail -n 1 "$log")

if [ "${result:0:9}" = "Succeeded" ]; then
    echo "### PASS"; exit 0

# Open the log file in case of failure.

open "$log"
echo "### FAIL"; exit 1