[GRASS-user] Re: Detect failure during batch job execution
Hamish
hamish_b at yahoo.com
Wed Dec 12 20:05:10 EST 2007
Tim Michelsen wrote:
> > Is there a way to detect whether an operation has succeeded or
> > failed?
Yes. The program will exit with an "exit code". For GRASS modules this
will be "0" on success and "1" on fail. I am not sure what a Seg-fault
or other abnormal termination returns.
you can test the exit code for the last command from the Bash prompt
with "$?".
For example:
g.module
echo $?
g.module
RESULT=$?
if [ $RESULT -ne 0 ] ; then
echo "it exited with an error"
fi
> > Or whether a vector layer exists or not?
> I am also interested into a solution on that.
g.findfile element=vector file=mapname
this will return various info about the map. You can set shell
variables with it directly:
eval `g.findfile element=vector file=roads`
echo "$fullname"
also the g.findfile return code is dependent on if the file was found
or not.
MAPNAME=roads
if [ `g.findfile element=vector file="$MAPNAME"` -eq 0 ] ; then
d.vect $MAPNAME
fi
same as
eval `g.findfile element=vector file="$MAPNAME"`
if [ -n "$name" ] ; then
d.vect $MAPNAME
fi
> I have been saving log to file using
> command > grass.log 2>&1
>
> But this doensn't say anything about the result of the operation...
If it exits with an error there will be "ERROR: ...." or a
"Segmentation Fault" text. No output generally means everything was ok.
Note some modules may successfully exit haven written 0 features, e.g.
v.extract where="x != x".
Hamish
____________________________________________________________________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping
More information about the grass-user
mailing list