Esempio n. 1
0
        public static void RedirectToParent(bool throwOnFailure = false)
        {
            var stdoutRedirected = IsHandleRedirected(Win32Native.GetStdHandle(STDOUT_HANDLE_NAME));

            if (stdoutRedirected)
            {
                var stdoutStream = Console.Out;
            }

            var stderrRedirected = IsHandleRedirected(Win32Native.GetStdHandle(STDERR_HANDLE_NAME));

            if (stderrRedirected)
            {
                var stderrStream = Console.Error;
            }

            if (!Win32Native.AttachConsole(ATTACH_PARENT_PROCESS) && throwOnFailure)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            if (!stderrRedirected)
            {
                Win32Native.SetStdHandle(STDERR_HANDLE_NAME, Win32Native.GetStdHandle(STDOUT_HANDLE_NAME));
            }
        }