Branch: rosuav/process-check-run

Two features added to the Process module. Firstly, a simple wrapper
Process.check_run that calls and throws an error if the
exit code isn't 0; and secondly, a means for to leave
stderr attached to the console. The intention is for this to be used
for subprocess invocations that should normally succeed, but which
might fail under exceptional circumstances:

string build ={"pike/bin/pike", argv[0], "-x", argv[1]}))->stdout;

The intention is for this to run a process and return its stdout. I
could, of course, manually check:

mapping rc ={"pike/bin/pike", argv[0], "-x", argv[1]}));
if (rc->stderr != "") werror(rc->stderr);
if (rc->exitcode) exit(1, "Oops\n");

But with this proposal, the code would look like this:

string build = Process.check_run(({"pike/bin/pike", argv[0], "-x",
argv[1]}), (["stderr": "-"]))->stdout;

It's a fairly simple idiom (and it might be worth making check_run set
stderr to "-" by default), and 99% of the time, it'll do the same as
the equally-simple idiom that I currently use for any quick-and-dirty
scripts - but if something goes wrong, check_run will make sure that
you don't miss noticing it.

There are, broadly speaking, two ways for a subprocess to signal that
something went wrong: a message on stderr, or an exit code. They're
handled independently (check_run looks for the exit code, and setting
stderr to "-" lets the user notice an error message), so you can pick
and choose.

Is this something wanted in trunk?


Reply via email to