X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FSystem%2FConsole.cs;h=fe0f229e396b169123983fdb3292b672d18c83d3;hb=e2b2d181084848f3c5dde2788370db1b79893c69;hp=138cb57f924f7e54f25a26b484285d30aa28dc03;hpb=5a41149e94b0e23ac529a9756137bd9406971cf0;p=mono.git diff --git a/mcs/class/corlib/System/Console.cs b/mcs/class/corlib/System/Console.cs index 138cb57f924..fe0f229e396 100644 --- a/mcs/class/corlib/System/Console.cs +++ b/mcs/class/corlib/System/Console.cs @@ -89,10 +89,17 @@ namespace System } } #endif + internal static TextWriter stdout; private static TextWriter stderr; private static TextReader stdin; +#if NET_4_5 + static TextWriter console_stdout; + static TextWriter console_stderr; + static TextReader console_stdin; +#endif + static Console () { #if NET_2_1 @@ -138,27 +145,55 @@ namespace System static void SetupStreams (Encoding inputEncoding, Encoding outputEncoding) { - stderr = new UnexceptionalStreamWriter (OpenStandardError (0), outputEncoding); - ((StreamWriter)stderr).AutoFlush = true; - stderr = TextWriter.Synchronized (stderr, true); - #if !NET_2_1 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); + stdin = new CStreamReader (OpenStandardInput (0), inputEncoding); } else { #endif +#if FULL_AOT_RUNTIME + Type nslogwriter = Type.GetType ("MonoTouch.Foundation.NSLogWriter, monotouch, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"); + stdout = (TextWriter) Activator.CreateInstance (nslogwriter); +#else stdout = new UnexceptionalStreamWriter (OpenStandardOutput (0), outputEncoding); ((StreamWriter)stdout).AutoFlush = true; +#endif stdout = TextWriter.Synchronized (stdout, true); + +#if FULL_AOT_RUNTIME + stderr = (TextWriter) Activator.CreateInstance (nslogwriter); +#else + stderr = new UnexceptionalStreamWriter (OpenStandardError (0), outputEncoding); + ((StreamWriter)stderr).AutoFlush = true; +#endif + stderr = TextWriter.Synchronized (stderr, true); + stdin = new UnexceptionalStreamReader (OpenStandardInput (0), inputEncoding); stdin = TextReader.Synchronized (stdin); #if !NET_2_1 } #endif +#if NET_4_5 + console_stderr = stderr; + console_stdout = stdout; + console_stdin = stdin; +#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); GC.SuppressFinalize (stdin); @@ -182,6 +217,26 @@ namespace System } } +#if NET_4_5 + public static bool IsErrorRedirected { + get { + return stderr != console_stderr || ConsoleDriver.IsErrorRedirected; + } + } + + public static bool IsOutputRedirected { + get { + return stdout != console_stdout || ConsoleDriver.IsOutputRedirected; + } + } + + public static bool IsInputRedirected { + get { + return stdin != console_stdin || ConsoleDriver.IsInputRedirected; + } + } +#endif + private static Stream Open (IntPtr handle, FileAccess access, int bufferSize) { #if MOONLIGHT