标签:false using C# System 命令 WriteLine StartInfo DOS true
使用是Visual studio 2019软件,Pragram.cs代码如下
using System; using System.Collections; using System.Diagnostics; using System.Threading; using DefExcel = Microsoft.Office.Interop.Excel; namespace TestProcess { class Program { static void Main(string[] args) { #region // 实现C#操作Dos命令 Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; // 要执行的程序 p.StartInfo.UseShellExecute = false; // 不使用系统外壳程序启动 p.StartInfo.RedirectStandardInput = false; // 不重定向输入 p.StartInfo.RedirectStandardOutput = true; // 重定向输出 p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = true; // 不创建窗口 p.Start(); try { if (p.Start())//开始进程 { p.StandardInput.WriteLine("tasklist"); p.StandardInput.WriteLine("exit"); string output = p.StandardOutput.ReadToEnd();//读取进程的输出 Console.WriteLine($"{output}"); // 打印读取的内容 } } catch { Console.WriteLine("出现异常"); } finally { if (p != null) p.Close(); } #endregion } }
*********************************** 完成 ***********************************************
标签:false,using,C#,System,命令,WriteLine,StartInfo,DOS,true 来源: https://www.cnblogs.com/yimai-series/p/15063093.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。