2009-05-28 17 views
5

मैं दो सी # प्रक्रियाओं को कैसे जोड़ सकता हूं ताकि वे एक दूसरे के साथ stdin और stdout पर संवाद कर सकें? > Stdout एक - -> stdin बी ---> प्रक्रिया बीसी # द्वि-दिशात्मक आईपीसी stdin और stdout

प्रक्रिया एक < - stdin एक < - stdout बी < --- प्रक्रिया

प्रक्रिया एक:

इस तरह

बी

उत्तर

4
using System; 
using System.Diagnostics; 

class Program 
{ 
    static void Main(string[] args) 
    { 
    string name; 
    if (args.Length > 0 && args[0] == "slave") 
    { 
     name = "slave"; 
    } 
    else 
    { 
     name = "master"; 
     var info = new ProcessStartInfo(); 
     info.FileName = "BidirConsole.exe"; 
     info.Arguments = "slave"; 
     info.RedirectStandardInput = true; 
     info.RedirectStandardOutput = true; 
     info.UseShellExecute = false; 
     var other = Process.Start(info); 
     Console.SetIn(other.StandardOutput); 
     Console.SetOut(other.StandardInput); 
    } 
    Console.WriteLine(name + " started."); 
    while (true) 
    { 
     var incoming = Console.ReadLine(); 
     var outgoing = name + " got : " + incoming; 
     Console.WriteLine(outgoing); 
     System.Threading.Thread.Sleep(100); 
    } 
    } 
} 
संबंधित मुद्दे