www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - D and cygwin io.

reply dcoder <dcoder devnull.com> writes:
Hello.  Here's a short program that works in a dos window:

import std.stdio;

void main() {

  writef( "What is your name?");

  string name = readln();
  writefln( "Hello " ~ name);
}

The program prints a prompt without a newline and the user enters a name and a
greeting is printed.

The same program does not seem to work when at a cygwin prompt.  The program
seems to pause.  It is actually waiting for input.  So, if I type in a name
and hit return, the prompt and the greeting appears as expected but on one line.

I can change writef to writefln and it will work on the cygwin prompt and on
the dos prompt, but now a newline will be added after the prompt message.

I'm wondering how can I fix this?  I am using bash shell on cygwin.


thanks.
Jul 27 2010
parent Rory Mcguire <rjmcguire gm_no_ail.com> writes:
dcoder wrote:

 Hello.  Here's a short program that works in a dos window:
 
 import std.stdio;
 
 void main() {
 
   writef( "What is your name?");
 
   string name = readln();
   writefln( "Hello " ~ name);
 }
 
 The program prints a prompt without a newline and the user enters a name
 and a greeting is printed.
 
 The same program does not seem to work when at a cygwin prompt.  The
 program
 seems to pause.  It is actually waiting for input.  So, if I type in a
 name and hit return, the prompt and the greeting appears as expected but
 on one line.
 
 I can change writef to writefln and it will work on the cygwin prompt and
 on the dos prompt, but now a newline will be added after the prompt
 message.
 
 I'm wondering how can I fix this?  I am using bash shell on cygwin.
 
 
 thanks.
try flushing the output after the write: stdout.flush();
Jul 27 2010