Beispiel #1
0
 private void CreateStdErrPipe()
 {
     stdErr = new Pipe();
     if (!Interop.ConsoleApi.SetStdHandle(StdHandle.ErrorHandle, stdErr.Write.DangerousGetHandle()))
     {
         throw InteropException.CreateWithInnerHResultException("Could not redirect STDERR.");
     }
     Error = new FileStream(stdErr.Read, FileAccess.Read);
 }
Beispiel #2
0
 private void CreateStdInPipe()
 {
     stdIn = new Pipe();
     if (!Interop.ConsoleApi.SetStdHandle(StdHandle.InputHandle, stdIn.Read.DangerousGetHandle()))
     {
         throw InteropException.CreateWithInnerHResultException("Could not redirect STDIN.");
     }
     Input = new FileStream(stdIn.Write, FileAccess.Write);
 }
Beispiel #3
0
 private void CreateStdOutPipe()
 {
     stdOut = new Pipe();
     if (!Interop.ConsoleApi.SetStdHandle(StdHandle.OutputHandle, stdOut.Write.DangerousGetHandle()))
     {
         throw InteropException.CreateWithInnerHResultException("Could not redirect STDOUT.");
     }
     Output = new FileStream(stdOut.Read, FileAccess.Read);
 }
Beispiel #4
0
        private void Initialise(bool hidden)
        {
            if (!Interop.ConsoleApi.AllocConsole())
            {
                throw InteropException.CreateWithInnerHResultException("Could not allocate console. You may need to FreeConsole first.");
            }

            handle = Interop.ConsoleApi.GetConsoleWindow();

            if (handle != IntPtr.Zero)
            {
                Interop.ConsoleApi.ShowWindow(handle, hidden ? ShowState.SwHide : ShowState.SwShowDefault);
            }

            RegisterOnCloseAction(ReleaseUnmanagedResources);

            CreateStdOutPipe();
            CreateStdErrPipe();
            CreateStdInPipe();
        }