www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - "The D Way" to run a sequence of executables?

reply Matthew OConnor <thegreendragon gmail.com> writes:
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?
Aug 24 2018
next sibling parent Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Friday, August 24, 2018 11:36:25 AM MDT Matthew OConnor via Digitalmars-
d-learn 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?
AFAIK, you're only two options are to either make consequitive calls to one of the execute family of functions where you check the return code and act accordingly (whether you use exceptions to deal with it is up to you, but either way, you have to check the result of each call to execute, since it doesn't throw), or you use one of the functions which uses the shell (e.g. executeShell) and write it out the way you would on the command-line with ||'s and/or &&'s. Either way, Phobos doesn't provide any functions that are specifically for calling a sequence of executables rather than just one. So, you're going to have to figure out how to put that together in a way that works best for you and what you're doing given what std.process has. - Jonathan M Davis
Aug 24 2018
prev sibling next sibling parent Chris M. <chrismohrfeld comcast.net> writes:
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); }
Aug 24 2018
prev sibling next sibling parent reply JN <666total wp.pl> writes:
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?
It's kind of a dirty and not very portable solution, but if you run by executeShell, you could so something like executeShell("cmd1 && cmd2 && cmd3") and let the shell do the sequence for you.
Aug 25 2018
parent JN <666total wp.pl> writes:
On Saturday, 25 August 2018 at 22:00:47 UTC, JN wrote:
 It's kind of a dirty and not very portable solution, but if you 
 run by executeShell, you could so something like 
 executeShell("cmd1 && cmd2 && cmd3") and let the shell do the 
 sequence for you.
Oops, didn't notice it was suggested already.
Aug 25 2018
prev sibling parent Kagamin <spam here.lot> writes:
Maybe http://libpipeline.nongnu.org/ can be an inspiration.
Aug 28 2018