Reading input from piped stdin.
Thomas
sitronvask at gmail.com
Fri Feb 14 11:26:14 PST 2014
On Friday, 14 February 2014 at 19:12:24 UTC, Steven Schveighoffer
wrote:
> On Fri, 14 Feb 2014 14:05:01 -0500, Thomas
> <sitronvask at gmail.com> wrote:
>
>> I'm new to D, and I find it quite enjoyable so far.
>> I have however stumbled upon a problem which I can't seem to
>> figure out.
>>
>> I am trying to make a program that creates a child process,
>> writes something to the child process stdin and reading from
>> its
>> stdout. I am going to use it later for testing out process pair
>> redundancy.
>>
>> Appearently the child blocks at "s = stdin.readln()". If I
>> remove
>> all writing to the child, and instead just read its output,
>> everything works fine. My code is attached below:
>
> stdin and stdout are buffered streams. Buffered streams in D
> only flush on newline when they are attached to a console
> (terminal window). Otherwise, they wait until the buffer is
> full before flushing. Buffer is probably about 4096 bytes.
>
> What is likely happening is that you are writing, it's going
> into the buffer, but not flushing, and then you are waiting for
> the response (which likely is also not flushing from the child
> process).
>
> Try adding flushes after each writeln.
>
> BTW, this is not really a D problem, you would have the same
> issue in C.
>
> -Steve
Ah, had to add after both writelns. Looks like that solved it.
Thanks!
More information about the Digitalmars-d-learn
mailing list