|
Este artículo se tradujo de forma manual. Mueva el puntero sobre las frases del artículo para ver el texto original.
|
Traducción
Original
|
Console.SetOut (Método)
Ensamblado: mscorlib (en mscorlib.dll)
[HostProtectionAttribute(SecurityAction.LinkDemand, UI = true)] public static void SetOut( TextWriter newOut )
Parámetros
- newOut
- Tipo: System.IO.TextWriter
Secuencia que constituye la nueva salida estándar.
| Excepción | Condición |
|---|---|
| ArgumentNullException |
|
| SecurityException |
Console.WriteLine("Hello World"); FileStream fs = new FileStream("Test.txt", FileMode.Create); // First, save the standard output. TextWriter tmp = Console.Out; StreamWriter sw = new StreamWriter(fs); Console.SetOut(sw); Console.WriteLine("Hello file"); Console.SetOut(tmp); Console.WriteLine("Hello World"); sw.Close();
Nota |
|---|
El atributo HostProtectionAttribute aplicado a este tipo o miembro tiene el siguiente valor de la propiedad Resources: UI. El atributo HostProtectionAttribute no afecta a las aplicaciones de escritorio (que normalmente se inician haciendo doble clic en un icono, escribiendo un comando o introduciendo una dirección URL en el explorador). Para obtener más información, vea la clase HostProtectionAttribute o Programación en SQL Server y atributos de protección de host. |
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; } }
- SecurityPermission
para llamar al código no administrado. Enumeración asociada: SecurityPermissionFlag.UnmanagedCode
Windows 7, Windows Vista SP1 o posterior, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (no se admite Server Core), Windows Server 2008 R2 (se admite Server Core con SP1 o posterior), Windows Server 2003 SP2
.NET Framework no admite todas las versiones de todas las plataformas. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.
Nota