在线等。。。急急急!!!

killyourdidi 2009-05-23 09:25:43
读取*.exe的输出显示到文本:
{
...
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "/c " + "\".....*.exe\"";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
reader = p.StandardOutput;
line = reader.ReadLine();


//1秒钟执行一次
time1 = new System.Timers.Timer();
time1.Enabled = true;
time1.Interval = 1000D;
time1.Elapsed+=new System.Timers.ElapsedEventHandler(time1_Elapsed);
...
}
...
private void time1_Elapsed(object sender, ElapsedEventArgs e)
{
while ((line != " Running:\n")&& (!reader.EndOfStream))
{
printInfo.AppendText(line);
line = reader.ReadLine();
}
if (line == " Running:\n")
{
printInfo.AppendText(line);
line = reader.ReadLine();
.........
}
if (reader.EndOfStream)///////结果没有显示完就执行了这句,求解????????
{
printInfo.AppendText(line);
time1.Enabled = false;
}
}
...全文
89 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
liyoubaidu 2009-05-30
  • 打赏
  • 举报
回复
up
济南大飞哥 2009-05-24
  • 打赏
  • 举报
回复
是不是线程问题?
aight 2009-05-24
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 wangkuang5 的回复:]
ErrorDataReceived本身在线程里
注意控件的委托调用
[/Quote]
帮忙顶了。
wangkuang5 2009-05-24
  • 打赏
  • 举报
回复
ErrorDataReceived本身在线程里
注意控件的委托调用
wangkuang5 2009-05-24
  • 打赏
  • 举报
回复

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);
//}
}
}


楼主给分吧,你思路是好,方法不对
killyourdidi 2009-05-23
  • 打赏
  • 举报
回复
不是1秒钟到了
比如说 应该分10次显示 也就是10秒 内容
结果只显示出了少于10秒的内容
os340223 2009-05-23
  • 打赏
  • 举报
回复
1秒钟到了?
niitnanfeng 2009-05-23
  • 打赏
  • 举报
回复
帮你顶

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧