110,567
社区成员
发帖
与我相关
我的任务
分享
BackgroundWorker bgw = (BackgroundWorker)sender;
string cmdinfo = e.Argument.ToString();
//MessageBox.Show(cmdinfo);
//if (!File.Exists("busybox.exe")) { MessageBox.Show("[busybox.exe] File isn't exists"); return; }
//if (!File.Exists("cygcrypt-0.dll")) { MessageBox.Show("[cygcrypt-0.dll] File isn't exists"); return; }
//if (!File.Exists("cygwin1.dll")) { MessageBox.Show("[cygwin1.dll] File isn't exists"); return; }
Process p = new Process();
//p.StartInfo.FileName = "busybox.exe";
ProcessStartInfo pstartinfo = new ProcessStartInfo("busybox.exe", cmdinfo);
p.StartInfo = pstartinfo;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived);//<---------在这里读你要的
p.ErrorDataReceived += new DataReceivedEventHandler(p_ErrorDataReceived);//<---------在这里读你要的
p.Exited += new EventHandler(p_Exited);
timer.Enabled = true;
p.Start();
busyboxProcessID = p.Id;
string strOutput = string.Empty;
//p.StandardInput.WriteLine(cmdinfo);
p.StandardInput.WriteLine("busybox.exe ps");
/*
E:\EMP600\workspace\WrtImg\WrtImg\bin\Release>busybox.exe dd bs=4096k if=H:\boot
\imgs\maxdos.img of=/dev/sdb
2+1 records in
2+1 records out
*/
p.BeginErrorReadLine();
p.BeginOutputReadLine();
//bool finished = false;
//while (!finished) {
// strOutput = p.StandardOutput.ReadLine();
// //strOutput = p.StandardOutput.ReadToEnd();
// MessageBox.Show(strOutput+"3");
// if (strOutput.Contains("records out")) {
// MessageBox.Show(strOutput);
// p.StandardInput.WriteLine("exit");
// finished = true;
// }
//}
p.WaitForExit();
////p.Kill();
p.Close();
--------------------------
void p_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
string strOutput = e.Data;
if (strOutput == null) return;
if (strOutput.Contains("records out"))
{
//MessageBox.Show("Done!" + e.Data);
MessageBox.Show("Create Finished!");
label4.Invoke(new SetLableText(delegate(string o) { label4.Text = o.ToString(); }), new object[] { "" });
buttonMake.Invoke (new buttonEnable(delegate(bool o) {buttonMake.Enabled =o;}), new object[] { true });
timer.Enabled = false;
timer.Stop();
timer.Close();
progressBar1.Invoke(new progresshandler(delegate(int value) { progressBar1.Value = value; }), 0);
closeform = true;
}
else {
label4.Invoke(new SetLableText(delegate(string o) { label4.Text += o.ToString(); }), new object[] { "waiting" });
//for (int i = 0; i > 10; i++)
//{
// Thread.Sleep(30);
// label4.Invoke(new SetLableText(delegate(string o) { label4.Text += o.ToString(); }), new object[] { " " });
// Thread.Sleep(30);
//}
}
}