ProcessTestWrite.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Threading;
using System.IO;
namespace ConsoleTest
{
class ProcessTestWrite
{
Process p = null;
public ProcessTestWrite()
{
p = new Process();
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.FileName = "ProcessTestRead.exe";
p.Start();
new Thread(this.run).Start();
}
public static void Main(String[] args)
{
ProcessTestWrite rtw = new ProcessTestWrite();
rtw.Send();
}
public void Send()
{
StreamWriter sw = p.StandardInput;
while (true)
{
sw.WriteLine("jxncwzb");
}
}
public void run()
{
StreamReader sr = p.StandardOutput;
while (true)
{
String strLine = sr.ReadLine();
if (strLine != null)
Console.WriteLine(strLine);
else
return;
}
}
}
}
ProcessTestRead.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace ConsoleTest
{
class ProcessTestRead
{
static void Main(string[] args)
{
TextReader tr = Console.In;
while (true)
{
string str = tr.ReadLine();
if (str!=null)
Console.WriteLine(str+":你好");
else
return;
}
}
}
}
用ProcessTestWrite.exe写入信息,用ProcessTestRead.exe读取信息
运行ProcessTestWrite.exe看看
发表于 @
2007年05月09日 13:40:00 | | 编辑|
举报| 收藏