Skip to content

statab.sh not issuing nonzero return code on error #1

@rpguiteras

Description

@rpguiteras

Initially this worked as intended but recently has ceased issuing a nonzero return code when the Stata do-file exits with error.

to try to trace out what is happening, I made just a few slight changes to your statab.sh file,

adding -echo $rc- right after the rc variable is created
commenting out the
rm "$log"
line and then adding
echo "$log"
echo $rc

so that I could examine what is happening and what may be getting missed.

When I run a properly working do-file (named "reducedForm.do"), I get what we expect:

ARE10165 /cygdrive/w/BD_Sanitation_Social/analysis(checkBatch *%) $ ./code/bin/statab.sh do code/reducedForm.do
0
reducedForm.log
0

and there is no error and the log-file concludes as we would expect.

(Note that -echo "$log"- returning reducedForm.log means (I think) that statab.sh is finding the .log file correctly.)

However, when I intentionally mess up reducedForm.do to cause an error, I get the same thing:

ARE10165 /cygdrive/w/BD_Sanitation_Social/analysis(checkBatch *%) $ ./code/bin/statab.sh do co de/reducedForm.do
0
reducedForm.log
0

Even though the .log file has an error at the end:

. boom
--Break--
r(1);

end of do-file
--Break--
r(1);

So I guess something is happening when creating the rc variable

$STATABATCH $cmd "$@" 2>&1 | tail -100 > $log.extra
rc=$?

or

    if egrep --before-context=1 --max-count=1 "^r\([0-9]+\);$" "$log"
    then
        rc=1
    fi

such that rc is not picking up the error in the log-file.

I've attached the slightly modified statab.sh file. (saved as .txt so that github will allow the attachment)

statab.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions