- 最後登錄
- 2024-4-12
- 在線時間
- 1 小時
- 註冊時間
- 2014-1-11
- 閱讀權限
- 20
- 精華
- 0
- UID
- 14030965
- 帖子
- 55
- 積分
- 1 點
- 潛水值
- 6030 米
| 本帖最後由 arthurliuliu 於 2015-3-19 08:36 AM 編輯
不清楚你的目的是什麼
但如果只是單純只是想用C#語法使用CMD指令
你可以試試這個
- public string cmd(string strinput)
- {
- System.Diagnostics.Process p = new System.Diagnostics.Process();
- p.StartInfo.FileName = "cmd.exe";
- p.StartInfo.UseShellExecute = false;
- p.StartInfo.RedirectStandardInput = true;
- p.StartInfo.RedirectStandardOutput = true;
- p.StartInfo.RedirectStandardError = true;
- p.StartInfo.CreateNoWindow = true; //不跳出cmd視窗
- string strOutput = null;
- p.Start();
- p.StandardInput.WriteLine(strinput);
- p.StandardInput.WriteLine("exit");
- strOutput = p.StandardOutput.ReadToEnd();//匯出整個執行過程
- p.WaitForExit();
- p.Close();
- return strOutput;
- }
複製代碼
... |
|