你好,请问如何让这个控制台写一行呢?我设法让它在你处理它时运行 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/