Beispiel #1
0
        public static StartupInfoWithOutputStreams Create()
        {
            var result = new StartupInfoWithOutputStreams();

            result.STARTUP_INFO    = new AdvApi32PInvoke.STARTUPINFO();
            result.STARTUP_INFO.cb = Marshal.SizeOf(typeof(AdvApi32PInvoke.STARTUPINFO));

            SafeFileHandle internalConsoleOutput;
            SafeFileHandle internalErrorOutput;
            SafeFileHandle consoleOutput;
            SafeFileHandle errorOutput;

            Win32Pipe.CreatePipe(out internalConsoleOutput, out consoleOutput, false);
            Win32Pipe.CreatePipe(out internalErrorOutput, out errorOutput, false);

            result.STARTUP_INFO.hStdInput  = Kernel32.GetStdHandle(Kernel32.STD_INPUT_HANDLE);
            result.STARTUP_INFO.hStdOutput = consoleOutput.DangerousGetHandle();
            result.STARTUP_INFO.hStdError  = errorOutput.DangerousGetHandle();
            result.STARTUP_INFO.dwFlags    = AdvApi32PInvoke.STARTF_USESTDHANDLES;

            Encoding encoding = Encoding.GetEncoding(Kernel32.GetConsoleOutputCP());

            result.ConsoleOutput = new StreamReader(new FileStream(internalConsoleOutput, FileAccess.Read, 0x1000, false), encoding, true, 0x1000);
            result.ErrorOutput   = new StreamReader(new FileStream(internalErrorOutput, FileAccess.Read, 0x1000, false), encoding, true, 0x1000);

            return(result);
        }
        public static StartupInfoWithOutputStreams Create()
        {
            var result = new StartupInfoWithOutputStreams();

            result.STARTUP_INFO = new AdvApi32PInvoke.STARTUPINFO();
            result.STARTUP_INFO.cb = Marshal.SizeOf(typeof(AdvApi32PInvoke.STARTUPINFO));

            SafeFileHandle internalConsoleOutput;
            SafeFileHandle internalErrorOutput;
            SafeFileHandle consoleOutput;
            SafeFileHandle errorOutput;

            Win32Pipe.CreatePipe(out internalConsoleOutput, out consoleOutput, false);
            Win32Pipe.CreatePipe(out internalErrorOutput, out errorOutput, false);

            result.STARTUP_INFO.hStdInput = Kernel32.GetStdHandle(Kernel32.STD_INPUT_HANDLE);
            result.STARTUP_INFO.hStdOutput = consoleOutput.DangerousGetHandle();
            result.STARTUP_INFO.hStdError = errorOutput.DangerousGetHandle();
            result.STARTUP_INFO.dwFlags = AdvApi32PInvoke.STARTF_USESTDHANDLES;

            Encoding encoding = Encoding.GetEncoding(Kernel32.GetConsoleOutputCP());
            result.ConsoleOutput = new StreamReader(new FileStream(internalConsoleOutput, FileAccess.Read, 0x1000, false), encoding, true, 0x1000);
            result.ErrorOutput = new StreamReader(new FileStream(internalErrorOutput, FileAccess.Read, 0x1000, false), encoding, true, 0x1000);

            return result;
        }