When the console command uses process. Start ();, the output content can be directly displayed. Of course, the output content is asynchronously displayed and the program ends. The Code is as follows:
Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Linq;
Using System. Text;
Using System. Windows. Forms;
Using System. Diagnostics;
Namespace testApplication1
{
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}
Private void button#click (object sender, EventArgs e)
{
Using (Process process = new System. Diagnostics. Process ())
{
Process. StartInfo. FileName = "ping ";
Process. StartInfo. Arguments = "127.0.0.1-t ";
Process. StartInfo. UseShellExecute = false;
Process. StartInfo. CreateNoWindow = true;
Process. StartInfo. RedirectStandardOutput = true;
Process. Start ();
Process. BeginOutputReadLine ();
Process. OutputDataReceived + = new DataReceivedEventHandler (process_OutputDataReceived );
}
}
Private void process_OutputDataReceived (object sender, DataReceivedEventArgs e)
{
If (! String. IsNullOrEmpty (e. Data ))
This. AppendText (e. Data + Environment. NewLine );
}
Public delegate void AppendTextCallback (string text );
& Nb