I need to Copy The Output CMD lines to textbox is that possible ? 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();
because ReadLine
will wait until data is available or the stream is closed. When the stream is closed, ReadLine
will return null
.
string line;
while ((line = proc.StandardOutput.ReadLine())!=null)
{
// textbox.text = line or something like that
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.