X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org X-VirusChecked: Checked X-Env-Sender: A DOT Hall AT servicepower DOT com X-Msg-Ref: server-12.tower-116.messagelabs.com!1236741243!32221079!1 X-StarScan-Version: 6.0.0; banners=-,-,- Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: Bash sometimes writes to stdout in MS_DOS format. Date: Tue, 10 Mar 2009 23:13:39 -0400 Message-ID: <0FF3B6512477714C939F9B6310F6F97A02CE1356@loui-dc1.sp.servicepower.com> From: "Andy Hall" To: X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com I am having a very strange problem with bash 3.2.48-21 It goes like this. =46rom a bash shell I invoke another bash shell as follows:=20 ERROR_LOG=3D"/tmp/error.$$.log" BUILD_LOG=3D"/tmp/build.$$.log" ... ./$PRODUCT_CMD" >"$BUILD_LOG" 2>"$ERROR_LOG" All my files are mounted in binmode E.g. C:\cygwin\bin on /usr/bin type system (binmode) C:\cygwin\lib on /usr/lib type system (binmode) C:\cygwin on / type system (binmode) c: on /cygdrive/c type system (binmode,noumount) d: on /cygdrive/d type system (binmode,noumount) If $PRODUCT_CMD encounters an error, it will execute the following function to write an error message to stderr and stdout and exit with a specified non-zero exit code.=20 errmsg () { # Error information is written to the stderr in the # form of parameter settings that can be read by a # parent shell echo "BUILD_MASTER=3D\"$BUILD_MASTER\"" 1>&2 echo "PRODUCT_ENGINEERS=3D\"$PRODUCT_ENGINEERS\"" 1>&2 echo "ERROR_MESSAGE=3D\"$1\"" 1>&2 # Log message to stdout as well. [ "$1" !=3D "" ] && echo "$1" [ "$2" !=3D "" ] && exit $2 } The parent command on getting a non-zero exit code. Does the following. . "$ERROR_LOG" Now here is the strange stuff. 1. If I start the parent script from a bash window, this all works fine. If the child script exits with a non-zero exit code, the "." command reads the $ERROR_LOG without a problem.=20 2. If the parent script is started by a Windows task running as the cygwin user, the $ERROR_LOG will SOMETIMES be written in DOS format with CR LF line endings. It seems to depend on the depth of function nesting at the time errmsg is invoked. It is as if bash "forgets" some attribute of file descriptor 2 under some curious circumstances. This is totally repeatable. All I have to do is induce certain errors detectable by the child script, $PROGRAM_CMD. I have been unable to create a simple test case that exhibits this behavior, probably because of #1.=20 The scripts are pretty much platform independent and run on Linux, Solaris and HP-UX without a problem. There are only a few things which are platform dependent. I can of course inject a work-around if the script is running in the cygwin environment. I am wondering if anybody has any plausible explanation for this.=20=20 Andy Hall -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/