Bidirectional PIPE, and do not wait for child to terminate
Justin Whear via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jul 1 08:32:31 PDT 2014
On Tue, 01 Jul 2014 13:00:47 +0000, seany wrote:
> I read the manual here:
> http://dlang.org/phobos/std_process.html#.spawnProcess
>
> However, I need to (I can not remember, nor can I find in the forums any
> info thereon) create
>
> 1. Bidirectional Pipes - I would like to write something to a second
> program (UNIX, resp GNU/LINUX environment) and listen to what it has to
> say.
>
> 2. I would like to continue with my program when the child process has
> spawned (the child process is guaranteed to terminate), unlike wait, and
> trywait does not seem to guarantee that the parent process will
> continue.
>
> Help? Please.
A pipe can be unidirectional only, but you can use more than one. In
this case, you want to create at least two files in the parent process,
one open for writing and one for reading. Pass the one open for writing
as the child's stdin, the one for reading as the child's stdout. This
will allow you to write to and read from the child.
Regarding your second question, spawnProcess is not blocking, so the
parent process will continue execution immediately. Unless you mean you
want the child process to outlive the parent, in which case...
Having the parent terminate without causing problems for the child is a
tricky issue. Here's why: when the parent terminates, the child is going
to be unowned and have its stdin and stdout closed (because the parent's
ends are closed). It is possible to reown the process (to nohup for
instance), but I'm not sure what you can do about the closed stdin and
stdout.
More information about the Digitalmars-d-learn
mailing list