public static void SetOut(TextWriter newOut) { if (newOut == null) { throw new ArgumentNullException("newOut"); } stdout = newOut; IsOutputRedirected = newOut != _stdout; }
public static void SetError(TextWriter newError) { if (newError == null) { throw new ArgumentNullException("newError"); } stderr = newError; IsErrorRedirected = newError != _stderr; }
public static void ResetOut() { stdout = _stdout; IsOutputRedirected = false; }
public static void ResetError() { stderr = _stderr; IsErrorRedirected = false; }
private static void SetupStreams(Encoding inputEncoding, Encoding outputEncoding) { #if !NET_2_1 && !SSHARP if (!Environment.IsRunningOnWindows && ConsoleDriver.IsConsole) { StreamWriter w = new CStreamWriter(OpenStandardOutput(0), outputEncoding); w.AutoFlush = true; stdout = TextWriter.Synchronized(w, true); w = new CStreamWriter(OpenStandardOutput(0), outputEncoding); w.AutoFlush = true; stderr = TextWriter.Synchronized(w, true); #if CONSOLEIN stdin = new CStreamReader(OpenStandardInput(0), inputEncoding); #endif } else { #endif // FULL_AOT_RUNTIME is used (instead of MONOTOUCH) since we only want this code when running on // iOS (simulator or devices) and *not* when running tools (e.g. btouch #12179) that needs to use // the mscorlib.dll shipped with Xamarin.iOS #if MONOTOUCH && FULL_AOT_RUNTIME stdout = new NSLogWriter(); #else #if SSHARP stdout = new StdTextWriter(); #else stdout = new UnexceptionalStreamWriter(OpenStandardOutput(0), outputEncoding); ((StreamWriter)stdout).AutoFlush = true; #endif #endif stdout = TextWriter.Synchronized(stdout, true); #if MONOTOUCH && FULL_AOT_RUNTIME stderr = new NSLogWriter(); #else #if SSHARP stderr = new StdErrWriter(); #else stderr = new UnexceptionalStreamWriter(OpenStandardError(0), outputEncoding); ((StreamWriter)stderr).AutoFlush = true; #endif #endif stderr = TextWriter.Synchronized(stderr, true); #if CONSOLEIN stdin = new UnexceptionalStreamReader(OpenStandardInput(0), inputEncoding); stdin = TextReader.Synchronized(stdin); #endif #if !NET_2_1 && !SSHARP } #endif #if MONODROID if (LogcatTextWriter.IsRunningOnAndroid()) { stdout = TextWriter.Synchronized(new LogcatTextWriter("mono-stdout", stdout)); stderr = TextWriter.Synchronized(new LogcatTextWriter("mono-stderr", stderr)); } #endif // MONODROID GC.SuppressFinalize(stdout); GC.SuppressFinalize(stderr); #if CONSOLEIN GC.SuppressFinalize(stdin); #endif #if SSHARP IsOutputRedirected = false; IsErrorRedirected = false; #endif }
static Console() { #if NET_2_1 || SSHARP #if CONSOLEIN Encoding inputEncoding; #endif Encoding outputEncoding; #endif #if !SSHARP if (Environment.IsRunningOnWindows) #endif { // // On Windows, follow the Windows tradition // #if NET_2_1 // should never happen since Moonlight does not run on windows inputEncoding = outputEncoding = Encoding.Default; #else try { #if CONSOLEIN inputEncoding = Encoding.GetEncoding(WindowsConsole.GetInputCodePage()); #endif outputEncoding = Encoding.GetEncoding(WindowsConsole.GetOutputCodePage()); // ArgumentException and NotSupportedException can be thrown as well } catch { #if CONSOLEIN // FIXME: I18N assemblies are not available when compiling mcs // Use Latin 1 as it is fast and UTF-8 is never used as console code page inputEncoding = #endif outputEncoding = Encoding.Default; } #endif } #if !SSHARP else { // // On Unix systems (128), do not output the // UTF-8 ZWNBSP (zero-width non-breaking space). // int code_page = 0; Encoding.InternalCodePage(ref code_page); if (code_page != -1 && ((code_page & 0x0fffffff) == 3 || // UTF8Encoding.UTF8_CODE_PAGE ((code_page & 0x10000000) != 0))) { inputEncoding = outputEncoding = Encoding.UTF8Unmarked; } else { inputEncoding = outputEncoding = Encoding.Default; } } #endif #if CONSOLEIN SetupStreams(inputEncoding, outputEncoding); #else SetupStreams(null, outputEncoding); #endif #if SSHARP _stdout = stdout; _stderr = stderr; #endif }