有没有办法表明像标准计算器这样的过程是否有输出,
我需要它,因为我有这一行:
sr = p1.StandardOutput;
我需要这样做:
s = sr.ReadLine();
仅当有输出时p1
例如,在计算器中,没有输出,因此程序在ReadLine
.
谢谢大家。
代码 :
while (i < asProcesses.Length - 1)
{
if ((i + 1) == asProcesses.Length - 1 && sOutRedirect != "")
break;
p1.StartInfo.RedirectStandardOutput = true;
p1.StartInfo.FileName = asProcesses[i];
p1.StartInfo.UseShellExecute = false;
if(i==0)
p1.Start();
sr = p1.StandardOutput;
Process p2 = new Process();
p2.StartInfo.RedirectStandardInput = true;
p2.StartInfo.FileName = asProcesses[i + 1];
p2.StartInfo.UseShellExecute = false;
p2.Start();
sw = p2.StandardInput;
while (!sr.EndOfStream && s != null)
{
s = sr.ReadLine();
if (s != null)
{
sw.WriteLine(s);
}
}
if (sw != null)
sw.Close();
if (sr != null)
sr.Close();
i++;
}
void foo()
{
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "c:\\windows\\system32\\ping.exe";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.EnableRaisingEvents = true;
p.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(p_OutputDataReceived);
p.Start();
p.BeginOutputReadLine();
}
void p_OutputDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
{
string s = e.Data;
// process s
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)