Spawning a process: Can I "have my cake and eat it too"?
Steven Schveighoffer
schveiguy at yahoo.com
Fri Mar 2 14:23:01 UTC 2018
On 3/1/18 11:50 PM, Nick Sabalausky (Abscissa) wrote:
> I'd like to include this functionality in Scriptlike, but I don't know
> if it's even possible:
>
> Launch a process (spawnProcess, pipeShell, etc) so the child's
> stdout/stderr go to the parent's stdout/stderr *without* the possibility
> of them getting inadvertently reordered/reinterleaved when viewed on the
> terminal, *and* still allow the parent to read the child's stdout and
> stderr?
>
> How could this be accomplished? Is it even possible?
You'd have to do this in the parent. You can duplicate the file
descriptor, so that writing to either goes to the same spot, but you
can't "fork" the file descriptor, so that writing to one goes to 2 spots.
With Phobos's std.process, you would have to allocate a buffer to store
the data as you read from the pipe and wrote it to the terminal, it
wouldn't be automatic.
I can think of an easy way to do it in iopipe, but it still would be
dependent on the reader actually reading the data from the pipe. In
other words, it wouldn't come out when the child wrote, it would only
come out when the parent read. But this might be inherent in what you
want, because the only way to prevent interleaving is to control it all
from one place.
-Steve
More information about the Digitalmars-d-learn
mailing list