Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Standard streams
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===2000s: .NET === In [[C Sharp (programming language)|C#]] and other [[.NET Framework|.NET]] languages, the standard streams are referred to by <code>System.Console.In</code> (for stdin), <code>System.Console.Out</code> (for stdout) and <code>System.Console.Error</code> (for stderr).<ref>{{Cite web|url=https://referencesource.microsoft.com/#mscorlib/system/console.cs,34|title= .NET Framework 4.7.1, mscorlib, console.cs |website=Reference Source - Microsoft |access-date=2017-12-10 |url-status=live |archive-url= https://web.archive.org/web/20171210072215/https://referencesource.microsoft.com/#mscorlib/system/console.cs,34 |archive-date= Dec 10, 2017 }}</ref> Basic read and write capabilities for the stdin and stdout streams are also accessible directly through the class <code>System.Console</code> (e.g. <code>System.Console.WriteLine()</code> can be used instead of <code>System.Console.Out.WriteLine()</code>). <code>System.Console.In</code>, <code>System.Console.Out</code> and <code>System.Console.Error</code> are <code>System.IO.TextReader</code> (stdin) and <code>System.IO.TextWriter</code> (stdout, stderr) objects, which only allow access to the underlying standard streams on a text basis. Full binary access to the standard streams must be performed through the <code>System.IO.Stream</code> objects returned by <code>System.Console.OpenStandardInput()</code>, <code>System.Console.OpenStandardOutput()</code> and <code>System.Console.OpenStandardError()</code> respectively. <syntaxhighlight lang="c#"> // C# example public static int Main(string[] args) { try { string s = System.Console.In.ReadLine(); double number = double.Parse(s); System.Console.Out.WriteLine("Number is: {0:F3}", number); return 0; // If Parse() threw an exception } catch (ArgumentNullException) { System.Console.Error.WriteLine("No number was entered!"); } catch (FormatException) { System.Console.Error.WriteLine("The specified value is not a valid number!"); } catch (OverflowException) { System.Console.Error.WriteLine("The specified number is too big!"); } return -1; } </syntaxhighlight> <syntaxhighlight lang="vbnet"> ' Visual Basic .NET example Public Function Main() As Integer Try Dim s As String = System.Console.[In].ReadLine() Dim number As Double = Double.Parse(s) System.Console.Out.WriteLine("Number is: {0:F3}", number) Return 0 ' If Parse() threw an exception Catch ex As System.ArgumentNullException System.Console.[Error].WriteLine("No number was entered!") Catch ex2 As System.FormatException System.Console.[Error].WriteLine("The specified value is not a valid number!") Catch ex3 As System.OverflowException System.Console.[Error].WriteLine("The specified number is too big!") End Try Return -1 End Function </syntaxhighlight> When applying the <code>System.Diagnostics.Process</code> [[class (computer science)|class]] one can use the instance [[Property (programming)|properties]] <code>StandardInput</code>, <code>StandardOutput</code>, and <code>StandardError</code> of that class to access the standard streams of the process.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)