110,538
社区成员
发帖
与我相关
我的任务
分享
private void BTN_START_Click(object sender, EventArgs e)
{
new Thread(delegate()
{
Process m_Process = new Process();
m_Process.StartInfo.FileName = “help”;//这个可以正常输出,与控制台输出一致
//m_Process.StartInfo.FileName = "java";//这个没有输出,为啥?与控制台输出不一致
m_Process.StartInfo.UseShellExecute = false;
m_Process.StartInfo.RedirectStandardOutput = true;
m_Process.StartInfo.CreateNoWindow = true;
m_Process.OutputDataReceived += new DataReceivedEventHandler(Process_OutputDataReceived);
m_Process.Start();
m_Process.BeginOutputReadLine();
m_Process.WaitForExit();
m_Process.Close();
}).Start();
}
public delegate void OutputText(string text);
void Process_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
OutputText dl = new OutputText(delegate(string text)
{
if (text == null) return;
C_CONSOLE.AppendText(text);
C_CONSOLE.AppendText("\r\n");
C_CONSOLE.ScrollToCaret();
});
C_CONSOLE.BeginInvoke(dl, e.Data);
}