Discussion:
cygwin bash include scripting and error code return question
John Fairhall
2012-03-25 22:50:33 UTC
Permalink
Hi,

I have a cygwin bash script running on 32 bit XP.

I have a windows BAT script calling bash, like so:

-------------------
bash mainScript.sh 2>&1 | tee %LOGFILE%
bash mailBuild.sh %ERRORLEVEL% %LOGFILE%
-------------------


What I was hoping was that bash would propagate the shell script's return code to the external OS, but as far as I can see the windows ERRORLEVEL is always 0.

Is there a way to make bash do this?

John.
Linda Walsh
2012-03-26 00:45:58 UTC
Permalink
Post by John Fairhall
Hi,
I have a cygwin bash script running on 32 bit XP.
-------------------
bash mainScript.sh 2>&1 | tee %LOGFILE%
bash mailBuild.sh %ERRORLEVEL% %LOGFILE%
-------------------
What I was hoping was that bash would propagate the shell script's return code to the external OS, but as far as I can see the windows ERRORLEVEL is always 0.
Is there a way to make bash do this?
----
Question -- is %ERRORLEVEL% returning the value of bash or the value of 'tee'?
I am guessing it returns the value of 'tee'.

If you want to do what you are doing...um...

bash -o pipefail -c "mainScript.sh >| tee %LOGFILE%"



should do it...
John Fairhall
2012-03-26 05:24:19 UTC
Permalink
The pipe is definitely the problem.

If I have this:

bash mainScript.sh 2>&1
bash mailBuild.sh %ERRORLEVEL% %LOGFILE%

When I gimmick mainScript to exit with any non-zero value I get an ERRORLEVEL of 255.

However, when I do this:

bash -o pipefail mainScript.sh 2>&1 | tee $LOGFILE bash mailBuild.sh %ERRORLEVEL% %LOGFILE%

I always get a zero ERRORLEVEL.

When I try this:

bash -o pipefail -c "mainScript.sh 2>&1 | tee %LOGFILE%"
it errors with
bash: mainScript.sh: command not found

J.
Corinna Vinschen
2012-03-26 10:26:20 UTC
Permalink
Post by John Fairhall
The pipe is definitely the problem.
bash mainScript.sh 2>&1
bash mailBuild.sh %ERRORLEVEL% %LOGFILE%
When I gimmick mainScript to exit with any non-zero value I get an ERRORLEVEL of 255.
bash -o pipefail mainScript.sh 2>&1 | tee $LOGFILE bash mailBuild.sh %ERRORLEVEL% %LOGFILE%
I always get a zero ERRORLEVEL.
Sure. Consider that the pipe is not created by bash, but by cmd. What
you get is the exitcode of the last command in the pipe, which is tee.
Post by John Fairhall
bash -o pipefail -c "mainScript.sh 2>&1 | tee %LOGFILE%"
it errors with
bash: mainScript.sh: command not found
Sure. You're using the -c option, so you're trying to run mainScript.sh
as a command. I assume mainScript.sh is in the current working
directory. And the current working directory is not in $PATH. And it
shouldn't. Either use ./mainScript.sh or, better, the full path to
mainScript.sh since that makes you independent of your CWD.


Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Project Co-Leader cygwin AT cygwin DOT com
Red Hat
Loading...