www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How can I get notified when an process created by spawnShell() has

reply Marc <jckj33 gmail.com> writes:
I do need to start (up to 4 a time) processes in parallel but I'd 

the process exits. How can I do that in D?
Mar 07 2018
parent Basile B. <b2.temp gmx.com> writes:
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 

 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.
Mar 07 2018