www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Reading stdin in Windows 7

reply Stanislav Blinov <blinov loniir.ru> writes:
  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?
-- 

	
Aug 17 2010
next sibling parent reply Jesse Phillips <jessekphillips+D gmail.com> writes:
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
Aug 18 2010
parent Stanislav Blinov <blinov loniir.ru> writes:
  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. --
Aug 19 2010
prev sibling parent Adam Wall <agcwall gmailc.om> writes:
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"
Nov 14 2010