예제 #1
0
        internal static void CreateStdioPipes(NativeHelpers.STARTUPINFOEX si, out SafeFileHandle stdoutRead,
                                              out SafeFileHandle stdoutWrite, out SafeFileHandle stderrRead, out SafeFileHandle stderrWrite,
                                              out SafeFileHandle stdinRead, out SafeFileHandle stdinWrite)
        {
            NativeHelpers.SECURITY_ATTRIBUTES pipesec = new NativeHelpers.SECURITY_ATTRIBUTES();
            pipesec.bInheritHandle = true;

            if (!NativeMethods.CreatePipe(out stdoutRead, out stdoutWrite, pipesec, 0))
            {
                throw new Win32Exception("STDOUT pipe setup failed");
            }
            if (!NativeMethods.SetHandleInformation(stdoutRead, NativeHelpers.HandleFlags.INHERIT, 0))
            {
                throw new Win32Exception("STDOUT pipe handle setup failed");
            }

            if (!NativeMethods.CreatePipe(out stderrRead, out stderrWrite, pipesec, 0))
            {
                throw new Win32Exception("STDERR pipe setup failed");
            }
            if (!NativeMethods.SetHandleInformation(stderrRead, NativeHelpers.HandleFlags.INHERIT, 0))
            {
                throw new Win32Exception("STDERR pipe handle setup failed");
            }

            if (!NativeMethods.CreatePipe(out stdinRead, out stdinWrite, pipesec, 0))
            {
                throw new Win32Exception("STDIN pipe setup failed");
            }
            if (!NativeMethods.SetHandleInformation(stdinWrite, NativeHelpers.HandleFlags.INHERIT, 0))
            {
                throw new Win32Exception("STDIN pipe handle setup failed");
            }

            si.startupInfo.hStdOutput = stdoutWrite;
            si.startupInfo.hStdError  = stderrWrite;
            si.startupInfo.hStdInput  = stdinRead;
        }
예제 #2
0
 public static extern bool CreatePipe(
     out SafeFileHandle hReadPipe,
     out SafeFileHandle hWritePipe,
     NativeHelpers.SECURITY_ATTRIBUTES lpPipeAttributes,
     UInt32 nSize);