I'm working with C# and control CMD for coworker. I already implement control cmd and real time display to rich text box.
But real request was stack this message to rich text box. My program couldn't stack the cmd command (keep history of previous cmds).
Below code work with real time display. if i send "dir" then it could display what i want. But after below function then do other work for device and reenter below function and C# clear rich text box then display new thing.
But what i want is: don't remove previous work in rich text box (keep history). Want stack whole message in rich text box.
If this is not correct way then what is the other way? Not using rich text box? Like using just note pad?? is there anyone know how to implement this?
Here are my code example.
string cmd1 = @"cd\"; /////this section changed by user so just send variety cmd.
string cmd2 = @"cd device_control";
string cmd3 = @"dir/w";
ProcessStartInfo cmd = new ProcessStartInfo();
Process process = new Process();
cmd.FileName = @"cmd";
cmd.WindowStyle = ProcessWindowStyle.Normal;
cmd.CreateNoWindow = true; // cmd
cmd.UseShellExecute = false;
cmd.RedirectStandardOutput = true; /////// @@@@@@@@@@
cmd.RedirectStandardInput = true;
cmd.RedirectStandardError = true;
process.EnableRaisingEvents = true;
process.StartInfo = cmd;
process.Start();
process.StandardInput.Write(cmd1 + Environment.NewLine);
process.StandardInput.Write(cmd2 + Environment.NewLine);
process.StandardInput.Write(cmd3 + Environment.NewLine);
process.StandardInput.Close();
string result = process.StandardOutput.ReadToEnd();
richTextBox2.Text = result;
Above code working fine without history of cmds.
What i want is i will visit above function about 50 times. And this could work real time display but people want stack the message to richtext box (keep history of cmds) because people want see the full log.
How do I append commands to the richtext box, rather than overwriting the previous commands?