private void button2_Click(object sender, EventArgs e)
{
using (Process process = new Process())
{
ProcessStartInfo startInfo = new ProcessStartInfo();
//StartParameter
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C test2.exe 1 1024";
startInfo.UseShellExecute = false;
startInfo.RedirectStandardInput = false;
startInfo.RedirectStandardOutput = true;
startInfo.CreateNoWindow = true;
process.StartInfo = startInfo;
process.OutputDataReceived += new DataReceivedEventHandler(P_OutputDataReceived);
process.Start();
process.WaitForExit();
process.BeginOutputReadLine();
//var strResult = process.StandardOutput.ReadToEnd();
process.Close();
//MessageBox.Show(strResult);
}
}
public delegate void MyInvoke(string title);
public void SetText(string title)
{
if (title == null) return;
this.textBox1.AppendText(title + Environment.NewLine);
}
private void P_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
Console.WriteLine(e.Data);
if (this.textBox1.InvokeRequired)
{
this.textBox1.Invoke(new MyInvoke(SetText), e.Data);
}
else
{
this.textBox1.AppendText(e.Data);
}
}
