亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

用C#運行cmd.exe,需要輸入“Y”

用C#運行cmd.exe,需要輸入“Y”

C#
撒科打諢 2023-07-22 18:42:41
我想用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"); 還是不行我應該怎么辦?
查看完整描述

1 回答

?
喵喔喔

TA貢獻1735條經驗 獲得超5個贊

net use需要一個/y標志,所以你可以直接傳遞它。你不需要輸入它。您還可以像這樣簡化代碼:


Process proc = new Process();

proc.StartInfo.FileName = "net";

proc.StartInfo.Arguments = "use * /delete /y";

proc.StartInfo.UseShellExecute = true;

proc.StartInfo.RedirectStandardOutput = true;

proc.StartInfo.RedirectStandardError = true;

proc.StartInfo.CreateNoWindow = true;

proc.Start();


查看完整回答
反對 回復 2023-07-22
  • 1 回答
  • 0 關注
  • 204 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號