【发布时间】:2019-07-29 03:05:26
【问题描述】:
我想用 System.Diagnostics.Process 运行 cmd 命令:“net use * /delete”,但命令需要输入“Y”或“N”。
这是我的代码:
Process proc = new Process();
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.CreateNoWindow = true;
string dosLine = "/C echo y | net use * /delete";
proc.StartInfo.Arguments = dosLine;
proc.Start();
代码不起作用。 我也试过这个:
proc.StandardInput.WriteLine("net use * /delete");
proc.StandardInput.WriteLine("Y");
还是不行
我该怎么办?
【问题讨论】:
标签: c#