[英]How To Copy Process CMD.exe line to Textbox C#
I need to Copy The Output CMD lines to textbox is that possible ? 我需要将“输出CMD”行复制到文本框吗? if yes please Show me Some to know the way to deal with it 如果是的话,请告诉我一些了解的处理方式
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();
Use this, then line will contain whole output 使用它,那一行将包含整个输出
proc.Start();
string line = proc.StandardOutput.ReadToEnd();
or for one line 或一行
proc.Start();
string line = proc.StandardOutput.ReadLine();
and if you want output line by line then 如果要逐行输出
while (!proc.StandardOutput.EndOfStream) {
string line = proc.StandardOutput.ReadLine();
// do your stuff
}
or you can try this one too, first remove proc.WaitForExit();
或者您也可以尝试此操作,首先删除proc.WaitForExit();
because ReadLine
will wait until data is available or the stream is closed. 因为ReadLine
会等到数据可用或流关闭后再进行。 When the stream is closed, ReadLine
will return null
. 关闭流时, ReadLine
将返回null
。
string line;
while ((line = proc.StandardOutput.ReadLine())!=null)
{
// textbox.text = line or something like that
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.