我需要将输出CMD行复制到文本框中,这可能吗?如果是,请给我看一些,让我知道如何处理
enter code here
private void pictureBox1_Click(object sender, EventArgs e)
{
label10.Visible = true;
string cmd = "/c adb install BusyBox.apk ";
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.Arguments = cmd;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.UseShellExecute = false;
//proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
proc.WaitForExit();
pictureBox6.Visible = true;
label10.Text = "Installation Complete";
// MessageBox.Show("Install Complete ...");
DateTime Tthen = DateTime.Now;
do
{
Application.DoEvents();
} while (Tthen.AddSeconds(4) > DateTime.Now);
label10.Visible = false;
pictureBox6.Visible = false;
}
您已经根据需要设置了所有内容,唯一缺少的是:
string consoleOutput = proc.StandardOutput.ReadToEnd();
使用此选项,则行将包含整个输出
proc.Start();
string line = proc.StandardOutput.ReadToEnd();
或者对于单行
proc.Start();
string line = proc.StandardOutput.ReadLine();
如果你想逐行输出,那么
while (!proc.StandardOutput.EndOfStream) {
string line = proc.StandardOutput.ReadLine();
// do your stuff
}
或者您也可以尝试这个,首先删除proc.WaitForExit();
,因为ReadLine
将等待数据可用或流关闭。当流关闭时,ReadLine
将返回null
。
string line;
while ((line = proc.StandardOutput.ReadLine())!=null)
{
// textbox.text = line or something like that
}