Thread overview
Reading stdin in Windows 7
Aug 17, 2010
Stanislav Blinov
Aug 18, 2010
Jesse Phillips
Aug 19, 2010
Stanislav Blinov
Nov 14, 2010
Adam Wall
August 17, 2010
  Hello,

I'm receiving strange results with reading stdin on Windows 7. Consider this code:

module test;

import std.stdio;

void main(string[] args)
{
         foreach (int i, string line; lines(stdin))
         {
                 write(line);
         }
}

On Linux, if I do 'cat test.d | ./test' I get test.d contents on stdout. But on Windows 7, ('type test.d | ./test.exe') the output is this:

std.stdio.StdioException: Bad file descriptor
module test;

import std.stdio;

void main(string[] args)
{
         foreach (int i, string line; lines(stdin))
         {
                 writef(line);
         }
}

So I too get type.d contents on stdout, but preceeded by StdioException string. This happens with dmd 2.047 and 2.048.

Is this my error, dmd's, or Windows's piping?
-- 





August 18, 2010
Stanislav Blinov Wrote:

>   Hello,
> 
> I'm receiving strange results with reading stdin on Windows 7. Consider this code:
> 
> module test;
> 
> import std.stdio;
> 
> void main(string[] args)
> {
>          foreach (int i, string line; lines(stdin))
>          {
>                  write(line);
>          }
> }
> 
> On Linux, if I do 'cat test.d | ./test' I get test.d contents on stdout. But on Windows 7, ('type test.d | ./test.exe') the output is this:
> 
> std.stdio.StdioException: Bad file descriptor
> module test;
> 
> import std.stdio;
> 
> void main(string[] args)
> {
>          foreach (int i, string line; lines(stdin))
>          {
>                  writef(line);
>          }
> }
> 
> So I too get type.d contents on stdout, but preceeded by StdioException string. This happens with dmd 2.047 and 2.048.
> 
> Is this my error, dmd's, or Windows's piping?
> -- 

In my experience Windows hasn't gotten piping right. And it has been known to have bugs, this might be related: http://stackoverflow.com/questions/466801/python-piping-on-windows-why-does-this-not-work
August 19, 2010
 18.08.2010 17:54, Jesse Phillips wrote:
> In my experience Windows hasn't gotten piping right. And it has been known to have bugs, this might be related: http://stackoverflow.com/questions/466801/python-piping-on-windows-why-does-this-not-work
Thanks, I'll take a look at that.
-- 

	

November 14, 2010
I experience the exact same problem on Windows 7 64-bit.

> import std.stdio;
>
> int main() {
>     char[] buf;
>     while (stdin.readln(buf))
>         write(buf);
>     return 0;
> }

If compiled as "test.exe", running the following command:

> echo "test line 1" | test

Produces the following result:

> std.stdio.StdioException: Bad file descriptor
> "test line 1"
>