It is a code that shows CMD instructions in real time using cshop.
Take one line each using StandardOutput and transfer it to TextBox in real time.
There is a full source code below.
Download it and use it.
In addition, the important part at the bottom is marked in red.
if (textBox_cmd.Text == "cls") { this.Invoke((MethodInvoker)delegate { textBox_result.Text = String.Empty; }); return; } var proc = new Process() { StartInfo = new ProcessStartInfo("cmd.exe", "/c " + textBox_cmd.Text) { RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true, UseShellExecute = false }, EnableRaisingEvents = true }; proc.Start(); using (StreamReader reader = proc.StandardOutput) { string line; while ((line = reader.ReadLine()) != null) { Console.WriteLine(line); this.Invoke((MethodInvoker)delegate { textBox_result.AppendText(line + Environment.NewLine); }); } } proc.WaitForExit();
c# source code (Full code)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace REALTIME_CMD { public partial class Form_REALTIME_CMD : Form { public Form_REALTIME_CMD() { InitializeComponent(); } private void button_RUN_Click(object sender, EventArgs e) { 실행(); } private void 실행() { if (backgroundWorker_cmd.IsBusy != true) { backgroundWorker_cmd.RunWorkerAsync(); } } private void textBox_cmd_KeyDown(object sender, KeyEventArgs e) { if(e.KeyCode == Keys.Enter) { 실행(); } } private void backgroundWorker_cmd_DoWork(object sender, DoWorkEventArgs e) { if (textBox_cmd.Text == "cls") { this.Invoke((MethodInvoker)delegate { textBox_result.Text = String.Empty; }); return; } var proc = new Process() { StartInfo = new ProcessStartInfo("cmd.exe", "/c " + textBox_cmd.Text) { RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true, UseShellExecute = false }, EnableRaisingEvents = true }; proc.Start(); using (StreamReader reader = proc.StandardOutput) { string line; while ((line = reader.ReadLine()) != null) { Console.WriteLine(line); this.Invoke((MethodInvoker)delegate { textBox_result.AppendText(line + Environment.NewLine); }); } } proc.WaitForExit(); } } }
c# cmd output in real time
c# cmd 실시간
c# cmd 출력
c# cmd
c# cmd command
c# cmd 결과 출력
c# cmd 명령어
c# cmd 창 숨기기
c# cmd command result
c# cmd.commandtext
c# cmd command example
c# cmd command output
c# cmd command not working
c# cmd.commandtype
c# cmd 명령어 실행 결과
c# cmd 명령어 입력
c# cmd.commandtext = update
c# run cmd command output
c# run cmd command get output
c# run cmd command not working
c# run cmd command and get output
c# run cmd
c# run cmd command
c# run cmd with arguments
c# run cmd command from code as administrator
c# run cmd.exe with arguments
c# run cmd command in background
c# run cmd command from code and get output
c# run cmd command on remote computer
c# run cmd command with arguments
c# run cmd file with arguments
real time console output redirection c#
real time output redirection c#
real time redirection c#
real time c#
real time c# projects
real time c# example
update textbox real time c#
get real time c#
events in c# real time example
delegates and events in c# real time example