Acquires the standard output stream, which is set to a specified buffer size.
Assembly: mscorlib (in mscorlib.dll)
<HostProtectionAttribute(SecurityAction.LinkDemand, UI := True)> _ Public Shared Function OpenStandardOutput ( _ bufferSize As Integer _ ) As Stream
[HostProtectionAttribute(SecurityAction.LinkDemand, UI = true)] public static Stream OpenStandardOutput( int bufferSize )
[HostProtectionAttribute(SecurityAction::LinkDemand, UI = true)] public: static Stream^ OpenStandardOutput( int bufferSize )
[<HostProtectionAttribute(SecurityAction.LinkDemand, UI = true)>] static member OpenStandardOutput : bufferSize:int -> Stream
Parameters
- bufferSize
- Type: System.Int32
The internal stream buffer size.
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException |
bufferSize is less than or equal to zero. |
This method can be used to reacquire the standard output stream after it has been changed by the SetOut method.
Note
|
|---|
|
The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: UI. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes. |
The following example illustrates the use of the OpenStandardOutput method.
Imports System.IO Public Class InsertTabs Private Const tabSize As Integer = 4 Private Const usageText As String = "Usage: INSERTTABS inputfile.txt outputfile.txt" Public Shared Function Main(args() As String) As Integer Dim writer As StreamWriter = Nothing If args.Length < 2 Then Console.WriteLine(usageText) Return 1 End If Try ' Attempt to open output file. writer = New StreamWriter(args(1)) ' Redirect standard output from the console to the output file. Console.SetOut(writer) ' Redirect standard input from the console to the input file. Console.SetIn(New StreamReader(args(0))) Catch e As IOException Dim errorWriter As TextWriter = Console.Error errorWriter.WriteLine(e.Message) errorWriter.WriteLine(usageText) Return 1 End Try Dim line As String = Console.ReadLine() While line IsNot Nothing Dim newLine As String = line.Replace("".PadRight(tabSize, " "c), ControlChars.Tab) Console.WriteLine(newLine) line = Console.ReadLine() End While writer.Close() ' Recover the standard output stream so that a ' completion message can be displayed. Dim standardOutput As New StreamWriter(Console.OpenStandardOutput()) standardOutput.AutoFlush = True Console.SetOut(standardOutput) Console.WriteLine("INSERTTABS has completed the processing of {0}.", args(0)) Return 0 End Function End Class
using System; using System.IO; public class InsertTabs { private const int tabSize = 4; private const string usageText = "Usage: INSERTTABS inputfile.txt outputfile.txt"; public static int Main(string[] args) { StreamWriter writer = null; if (args.Length < 2) { Console.WriteLine(usageText); return 1; } try { // Attempt to open output file. writer = new StreamWriter(args[1]); // Redirect standard output from the console to the output file. Console.SetOut(writer); // Redirect standard input from the console to the input file. Console.SetIn(new StreamReader(args[0])); } catch(IOException e) { TextWriter errorWriter = Console.Error; errorWriter.WriteLine(e.Message); errorWriter.WriteLine(usageText); return 1; } string line; while ((line = Console.ReadLine()) != null) { string newLine = line.Replace(("").PadRight(tabSize, ' '), "\t"); Console.WriteLine(newLine); } writer.Close(); // Recover the standard output stream so that a // completion message can be displayed. StreamWriter standardOutput = new StreamWriter(Console.OpenStandardOutput()); standardOutput.AutoFlush = true; Console.SetOut(standardOutput); Console.WriteLine("INSERTTABS has completed the processing of {0}.", args[0]); return 0; } }
using namespace System; using namespace System::IO; int main() { array<String^>^args = Environment::GetCommandLineArgs(); const int tabSize = 4; String^ usageText = "Usage: INSERTTABS inputfile.txt outputfile.txt"; StreamWriter^ writer = nullptr; if ( args->Length < 3 ) { Console::WriteLine( usageText ); return 1; } try { // Attempt to open output file. writer = gcnew StreamWriter( args[ 2 ] ); // Redirect standard output from the console to the output file. Console::SetOut( writer ); // Redirect standard input from the console to the input file. Console::SetIn( gcnew StreamReader( args[ 1 ] ) ); } catch ( IOException^ e ) { TextWriter^ errorWriter = Console::Error; errorWriter->WriteLine( e->Message ); errorWriter->WriteLine( usageText ); return 1; } String^ line; while ( (line = Console::ReadLine()) != nullptr ) { String^ newLine = line->Replace( ((String^)"")->PadRight( tabSize, ' ' ), "\t" ); Console::WriteLine( newLine ); } writer->Close(); // Recover the standard output stream so that a // completion message can be displayed. StreamWriter^ standardOutput = gcnew StreamWriter( Console::OpenStandardOutput() ); standardOutput->AutoFlush = true; Console::SetOut( standardOutput ); Console::WriteLine( "INSERTTABS has completed the processing of {0}.", args[ 1 ] ); return 0; }
.NET Framework
Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0.NET Framework Client Profile
Supported in: 4, 3.5 SP1Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note