question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Console.Write() doesn't show output until a newline

See original GitHub issue

(from dotnet/corefx#8183 by @omajid)

On RHEL 7, Console.Write()'s output does not get displayed until a newline is used (or the program exits).

If you run the following application, you don’t see anything as the output until 10 seconds have passed. Then all of “HelloWorld!” appears at once.

 public static void Main(string[] args)
 {
     Console.Write("Hello World");
     Console.Out.Flush();
     Task.Delay(10000).Wait();
     Console.WriteLine("!");
 }

Console applications that do input/output may use a style like the following:

public static void Main(string[] args)
{
    Console.Write("Name: ");
    var name = Console.ReadLine();
    Console.WriteLine("Your name is '" + name + "'.");
}

This doesn’t work for me. You get no output at all at first. If you type in something (say “Foo”) and hit ENTER, then you see all of the output at once:

Name: Foo
Your name is 'Foo'.

If you don’t hit enter, then it seems like the application has hung. A Console.Out.Flush() doesn’t fix this, as in the following:

public static void Main(string[] args)
{
    Console.Write("Name: ");
    Console.Out.Flush();
    var name = Console.ReadLine();
    Console.WriteLine("Your name is '" + name + "'.");
}

I ran all the test cases while ssh’ed into the RHEL 7 VM.

$ dotnet --version
1.0.0-rc2-002538

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

4reactions
ellismgcommented, May 2, 2016

The customer experience is pretty bad, and it seems like most folks will hit this, so I’d consider it.

0reactions
analogrelaycommented, May 2, 2016

@brthor Nothing I know of in build needs to both capture and forward. When we launch csc we capture, but don’t forward. Everything else is forwarded.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I print a string to the console without a newline at ...
4 Answers. It sounds like you're trying to get rid of the newline. WriteLine prints a newline. Write doesn't.
Read more >
Console.WriteLine Method (System)
Writes the specified data, followed by the current line terminator, to the standard output stream.
Read more >
How to read and write in Console app in C#
WriteLine(), we are printing current date and time and cursor is moved to a new line, then using Console.Write() to print “Press <Enter>...
Read more >
How to Flush the Output of the Python Print Function
In this tutorial, you'll learn how to flush the output of Python's print function. You'll explore output stream buffering in Python using ...
Read more >
Strings Input and Output functions in C
The fputs() function can be used to output two strings in C without space in between as it does not transfer the control...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found