On Friday, 24 August 2018 at 17:36:25 UTC, Matthew OConnor wrote:
I'd like to run a sequence of executables with something like std.process.execute, but I would like the sequence to error out if one of the executables returns a non-zero return code. What is the recommended way to do this? A wrapper that throws exceptions? Checking return values?

Here'd be a neat way if you don't mind it not terminating early. The first call will need a dummy value for prevStatus where the status field is 0.

import std.typecons;

alias ExecuteTuple = Tuple!(int,"status",string,"output");

ExecuteTuple call(ExecuteTuple prevStatus, string process)
{
    import std.process;
    if (prevStatus.status != 0)
        return prevStatus;
    else
        return execute(process);
}

Reply via email to