On Wednesday, 7 March 2018 at 15:03:28 UTC, Marc wrote:
I do need to start (up to 4 a time) processes in parallel but I'd like to get notified (similar to C#'s Process.Exited Event) when the process exits. How can I do that in D?

You can use pipeShell and a control loop to check when the ProcessPipes it returns is done.

example:

```d
void main()
{
import std.stdio, std.process, std.conv, std.random, core.thread,
        std.algorithm, std.range;

    ProcessPipes[4] pp;
iota(0,4).each!(a => pp[a] = pipeShell("sleep " ~ uniform(1,20).to!string));
    while (pp[].any!(a => !tryWait(a.pid).terminated))
        Thread.sleep(dur!"msecs"(50));

    writeln("done");
}
```

You can wrap in a struct to hide the ugly bits.

Reply via email to