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:
- Created 7 years ago
- Comments:14 (14 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The customer experience is pretty bad, and it seems like most folks will hit this, so I’d consider it.
@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.