[GRASS-dev] How to get stop a script with an error in a function
Glynn Clements
glynn at gclements.plus.com
Fri Oct 15 12:58:04 EDT 2010
António Rocha wrote:
> > Check the exit code from the command. Commands should use a non-zero
> > exit code if there was an error.
> >
> > It would help to know exactly how the command is being run.
> >
> >
>
> Hi,
> You are absolutely right :)
> Among others, I'm using:
> grass.run_command("r.in.gdal", flags= 'k', overwrite = 'o', input = src_file, output = target_file)
if grass.run_command(...) != 0:
grass.fatal(...)
run_command and write_command return the exit code.
start_command, pipe_command, and feed_command return the Popen object;
you can check its .returncode attribute once it has terminated.
read_command and parse_command return the data written to the child's
stdout; there isn't any mechanism to retrieve the exit status for
these. OTOH, read_command is trivial to implement yourself if you need
this.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list