Hi,
If your purpose is to display something in a second console window then create two console applications and use Piped Streams.
As an example..
In the main application
static void Main(string[] args)
{
Process command = new Process();
ProcessStartInfo commandInfo = new ProcessStartInfo("ConsoleReceiver.exe");
commandInfo.UseShellExecute = true;
command.StartInfo = commandInfo;
command.Start();
System.Threading.Thread.Sleep(2000);
using (NamedPipeClientStream pipeClient =
new NamedPipeClientStream(".", "testpipe", PipeDirection.Out))
{
Console.Write("Attempting to connect to pipe...");
pipeClient.Connect();
Console.WriteLine("Connected to pipe.");
Console.WriteLine("There are currently {0} pipe server instances open.",
pipeClient.NumberOfServerInstances);
try
{
using (StreamWriter sw = new StreamWriter(pipeClient))
{
sw.AutoFlush = true;
sw.WriteLine("Hi I am Server. Do you know me?");
}
}
catch (IOException ex)
{
Console.WriteLine("ERROR: {0}", ex.Message);
}
}
Console.WriteLine("OK");
}
In a second console application (after compile you may copy it to the bin dir of main application or use absoulte path of this in the main application)
static void Main(string[] args)
{
using (NamedPipeServerStream pipeServer =
new NamedPipeServerStream("testpipe", PipeDirection.In))
{
Console.WriteLine("NamedPipeServerStream object created.");
Console.Write("Waiting for client connection...");
pipeServer.WaitForConnection();
Console.WriteLine("Client connected.");
using (StreamReader sr = new StreamReader(pipeServer))
{
string temp;
while ((temp = sr.ReadLine()) != null)
{
new StreamWriter(Console.OpenStandardOutput()).WriteLine(temp);
Console.WriteLine(temp);
Console.ReadLine();
}
}
}
}
Hope this helps