* cygwin bash include scripting and error code return question
@ 2012-03-25 22:50 John Fairhall
2012-03-26 0:46 ` Linda Walsh
0 siblings, 1 reply; 4+ messages in thread
From: John Fairhall @ 2012-03-25 22:50 UTC (permalink / raw)
To: cygwin
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.
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: cygwin bash include scripting and error code return question
2012-03-25 22:50 cygwin bash include scripting and error code return question John Fairhall
@ 2012-03-26 0:46 ` Linda Walsh
2012-03-26 5:24 ` John Fairhall
0 siblings, 1 reply; 4+ messages in thread
From: Linda Walsh @ 2012-03-26 0:46 UTC (permalink / raw)
To: John Fairhall, cygwin
John Fairhall wrote:
> 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?
----
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...
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: cygwin bash include scripting and error code return question
2012-03-26 0:46 ` Linda Walsh
@ 2012-03-26 5:24 ` John Fairhall
2012-03-26 10:27 ` Corinna Vinschen
0 siblings, 1 reply; 4+ messages in thread
From: John Fairhall @ 2012-03-26 5:24 UTC (permalink / raw)
To: cygwin
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.
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: cygwin bash include scripting and error code return question
2012-03-26 5:24 ` John Fairhall
@ 2012-03-26 10:27 ` Corinna Vinschen
0 siblings, 0 replies; 4+ messages in thread
From: Corinna Vinschen @ 2012-03-26 10:27 UTC (permalink / raw)
To: cygwin
On Mar 26 05:24, John Fairhall wrote:
> 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.
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.
> When I try this:
>
> 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
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-03-26 10:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-25 22:50 cygwin bash include scripting and error code return question John Fairhall
2012-03-26 0:46 ` Linda Walsh
2012-03-26 5:24 ` John Fairhall
2012-03-26 10:27 ` Corinna Vinschen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).