C#命令没有写一行

Tom*_*lic 1 c#

嗯,您好,我如何让这个控制台写一行?我设法使它在处理时运行cmd.exe,但它没有写入行.

private void button1_Click(object sender, EventArgs e)
    {
        if (textBox1.Text == "alpha")
        {
            progressBar1.Value = 100;
            if (progressBar1.Value == 100)
            {
                MessageBox.Show("Welcome back master!");
                System.Diagnostics.Process.Start(@"C:\Windows\System32\cmd.exe");
                Console.WriteLine("Hello!!!");
            }

        }
Run Code Online (Sandbox Code Playgroud)

Kei*_*las 8

如果你想与控制台进程交互,你需要这样做: -

var p = new Process
    {
        StartInfo =
            {
                FileName = "cmd.exe", 
                UseShellExecute = false, 
                RedirectStandardInput = true, 
                RedirectStandardOutput = true
            }
    };
p.Start();
var w = p.StandardInput;                
w.WriteLine("Dir");
w.WriteLine("Exit");            
var theDirectoryListing = p.StandardOutput.ReadToEnd();
p.WaitForExit();
w.Close();            
p.Close();
Run Code Online (Sandbox Code Playgroud)