www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - std.stream for stdin?

reply dsimcha <dsimcha yahoo.com> writes:
I've been trying to write some small Unix-style utilities that read data from
either a file or stdin, process it and write the results to stdout.  Is there
a way to create an object of the Stream class from Phobos or one of its
subclasses that treats stdin as an input stream?  I'd like to avoid using the
C standard file/stream I/O if possible, since it doesn't handle exceptions
automatically and is just in general butt ugly compared to Phobos's
implementation.
Jul 11 2008
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"dsimcha" <dsimcha yahoo.com> wrote in message 
news:g57v7m$ss1$1 digitalmars.com...
 I've been trying to write some small Unix-style utilities that read data 
 from
 either a file or stdin, process it and write the results to stdout.  Is 
 there
 a way to create an object of the Stream class from Phobos or one of its
 subclasses that treats stdin as an input stream?  I'd like to avoid using 
 the
 C standard file/stream I/O if possible, since it doesn't handle exceptions
 automatically and is just in general butt ugly compared to Phobos's
 implementation.
import std.cstream, and use the din object :)
Jul 11 2008
parent reply dsimch <dsimcha yahoo.com> writes:
How is this class supposed to be used?  I wrote a simple test program, and it
appears not to work the way other subclasses of Stream work.  Here's the test
program, which should just copy stdin to stdout, but seems to do absolutely
nothing.

void main () {
   foreach(char[] line; din) {
       writefln(line);
   }
}

Similar results occur when I use the readLine method.
Jul 11 2008
next sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"dsimch" <dsimcha yahoo.com> wrote in message 
news:g58520$188d$1 digitalmars.com...
 How is this class supposed to be used?  I wrote a simple test program, and 
 it
 appears not to work the way other subclasses of Stream work.  Here's the 
 test
 program, which should just copy stdin to stdout, but seems to do 
 absolutely nothing.

 void main () {
   foreach(char[] line; din) {
       writefln(line);
   }
 }

 Similar results occur when I use the readLine method.
*shrug* I never had any problems using it.
Jul 11 2008
prev sibling parent reply dsimcha <dsimcha yahoo.com> writes:
Never mind.  The problem was I had another test.exe file at a higher level in
my path.
Jul 11 2008
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"dsimcha" <dsimcha yahoo.com> wrote in message 
news:g587ej$1cp1$1 digitalmars.com...
 Never mind.  The problem was I had another test.exe file at a higher level 
 in my path.
I hate those kinds of issues ;)
Jul 11 2008