help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: $(shell ..) testing for the exit value


From: John Graham-Cumming
Subject: Re: $(shell ..) testing for the exit value
Date: Mon, 05 Sep 2005 09:18:02 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040208 Thunderbird/0.5 Mnenhy/0.6.0.104

Abramovitz, Norman wrote:
When using the $(shell ..) function, is there a way to retrieve the shell's exit value? The output from the invocation is parsed by
foreach and eval so I cannot return a string as an exit code.  The
following two lines are executed outside any rules.

No, but you could write your own $(shell) wrapper that gives you the exit code. For example,

    myshell = $(shell echo `$1` $$?)

$(myshell command) returns the output of command with the exit code of command appended. For example

    $(call myshell,echo hello john)

would return

    hello john 0

or

    $(call myshell,exit 3)

would return

    3

If you want to get really fancy you could make myshell return only the values return by the command and store the exit code in a variable. Here I use the GNU Make Standard Library and require GNU Make 3.80 since I'll use $(eval):

    include gmsl

    __myshell = $(shell echo `$1` $$?)

    myshell = $(eval __result := $(call __myshell,$1))
    $(eval MYSHELL_RESULT := $(call last,$(__result)))
    $(call chop,$(__result))

So doing $(call myshell,command) works just like $(shell command) but the return code of the command is stored in MYSHELL_RESULT. (Note I've only tested all this with bash and zsh).

John.
--
John Graham-Cumming
address@hidden

Home: http://www.jgc.org/
POPFile: http://getpopfile.org/

Sign up for my Spam and Anti-spam Newsletter
at http://www.jgc.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]