Just an FYI this question has been re-edited to be more concise.
I am working with .NET (whether help is in C# or VB, it doesn't matter). I have a console application, something basic:
using System;
namespace ConsolePrinter
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Output");
Console.ReadLine();
}
}
}
In my Winforms application, I need to redirect standard error and standard input, but NOT standard output. Standard output should continue to display in the console window. By making a simple Winforms project and starting the above console EXE as a Process object, I can still view the console's output within the summoned console. As soon as I redirect standard error, the output disappears from the console window and all that displays is a blank console.
Here is an example Winforms project:
using System;
using System.Windows.Forms;
using System.Diagnostics;
namespace winformstest2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Process proc = new Process();
proc.StartInfo.FileName = "ConsolePrinter.exe";
//proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.UseShellExecute = false;
proc.Start();
}
}
}
This code works as intended. Uncommenting that commented line provides the error I'm talking about.
I have tried just attaching forms to a console project, but unfortunately I need to show and hide the console frequently, so starting the console application as a process is ideal. Using Win32 API was also a thought, but the user should not be able to close the entire application by closing the console, which AllocConsole() and other Win32 API calls would cause as a bi-product of their use.
Any help is appreciated, thank you!