Subject: Re: [Boost-build] exit code from SHELL
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2010-07-24 00:14:35
Ray Lambert wrote:
> I'm having a minor problem with getting exit codes from SHELL and I'm
> hoping someone might know what's happening.
> I'm invoking a Python script via the SHELL rule to perform some
> pre-build activities. When I run the script manually I get a return
> code of either 0 or 1 (as intended):
> $ ./prebuild.py; echo $?
> When I run it using SHELL, if the script tries to return 0 SHELL also
> returns 0 but when the script tries to return 1 SHELL returns 256
> local result = [ SHELL "./prebuild.py" : exit-code ] ;
> echo $(result) ;
> (outputs "256").
> I wanted to test for " $(result) == 1 " but that obviously fails if
> I get 256 back. For now, my work around is " if $(result) != 0 ".
> I looked at the bjam source code and found that the exit code is just
> the result of pclose(). However, I can't find any return value of 256
> defined on my system (Fedora 12).
> I looked at the pclose() man page and examined all related pages
> (pclose() apparently calls wait4() which apparently calls waitpid())
> and I also scoured the system header files and I can't find any 256
> value defined.
> Note that when SHELL returns 256 the script does run successfully.
> Anyone have any idea where this 256 is coming from or what it means?
I'm guessing that the exit code is actually the high byte of
the result of pclose. (This is a result of the way waitpid encodes
normal termination vs. termination on a signal). If the script
returns 2, do you get 512? To get the actual exit code, bjam
would need to use WIFEXITED/WEXITCODE.
Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk