C#命令不写一行

标签 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!!!");
            }

        }

最佳答案

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

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();

关于C#命令不写一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16073338/

相关文章:

c# - 如果字符串值不为 null 或为空,则在字符串中添加 "| "

c# - WPF/MVVM 选项卡式设计和避免绑定(bind)错误

c# - 如何使用 C# 裁剪扫描图像?

c# - 在 RedirectToAction 中传递对象

c# - 生成datalist次数

c# - C# 中 Convert.ToString() 和 .ToString() 的区别?

c# - 无法在 asp.net MVC 中使用 File.WriteAllBytes(),无法从方法组中选择方法您是否打算调用该方法?

c# - 是否可以将 web.config 中的 App 设置传递给 Common C# 类

c# - 使用单个查询更新两个表

C# 阻止 webbrowser 控件加载图像、flash、脚本等