问题描述
当父进程启动子进程,并获取子进程输出信息时,出现了输出框不断输出重复信息的现象,代码如下。使用相同的命令行参数,用cmd直接运行子程序,可以正常运行。
using (Process p = new Process())
{
p.StartInfo.FileName = "java.exe";
p.StartInfo.UseShellExecute = false; //是否使用操作系统shell启动
p.StartInfo.RedirectStandardInput = false; //接受来自调用程序的输入信息
p.StartInfo.RedirectStandardOutput = true; //由调用程序获取输出信息
p.StartInfo.RedirectStandardError = true; //重定向标准错误输出
p.StartInfo.CreateNoWindow = true; //不显示程序窗口
p.StartInfo.Arguments = argumentsFortheJarFile;
bool bStart = p.Start();
if (!bStart) //启动程序
{
Console.WriteLine("未能启动程序:" + jarPath);
return;
}