I know that there\'re stdout/in/err for a program and I want to redirect a program\'s output to a file instead of the console output. And I now figure it out with the code b
You can get a hold of the application's stdout by calling Console.OpenStandardOutput. From there, you can do whatever you want with the stream, although you won't be able to reassign it. If you want to do that you'll have to P/Invoke SetStdHandle and handle the details yourself.
EDIT: Added example code for the P/Invoke route:
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetStdHandle(int nStdHandle, IntPtr nHandle);
const int STD_OUTPUT_HANDLE = -11;
static void RedirectStandardOutput(FileStream file)
{
SetStdHandle(STD_OUTPUT_HANDLE, file.SafeFileHandle.DangerousGetHandle());
}