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); }
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); }
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); }
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(); }