• 用Dos黑窗口运行Cmd命令


     public class BlackWindow

        {

            private static BlackWindow _instance;

            public static BlackWindow Instance

            {

                get

                {

                    if (_instance == null)

                        _instance = new BlackWindow();

                    return _instance;

                }

            }     

            public System.Diagnostics.Process pro { set; get; }

            BlackWindow()

            {

                //下面StartInfo的UseShellExecute和RedirectStandardInput/Output选项为互斥选项

                //若设置UseShellExecute=true代表使用dos黑窗口,但RedirectStandardInput/Output必须为false,表示输入输出也只能通过dos窗口手工录入,不能通过StandardInput.WriteLine输入

                //若要显示Dos窗口,但又想通过程序输入命令,只能用StartInfo.Arguments = cmdLine;但该参数只能输入一行

                //StartInfo.Arguments命令前一定要加/k表示打开新窗口,否则运行结果无法显示

                pro = new System.Diagnostics.Process();

                pro.StartInfo.FileName = "cmd.exe";

                //pro.StartInfo.UseShellExecute = false; //true代表使用dos窗口,默认true

                //pro.StartInfo.RedirectStandardInput = true;

                // pro.StartInfo.RedirectStandardOutput = true;

                //pro.StartInfo.CreateNoWindow = true;           

            }

            public void Start(string cmdLine)

            {

                pro.StartInfo.Arguments = cmdLine;

                pro.StartInfo.WorkingDirectory = "";//工作目录

                pro.Start();

                //pro.StandardInput.WriteLine(cmdLine);

                pro.WaitForExit();

                pro.Close();           

            }

        }

  • 相关阅读:
    Using Change Management and Change Control Within a Project
    swift3.0 label改变行间距
    swift清理缓存
    Alamofire的get请求,post请求,以及上传字典
    swift跳转时隐藏tabbar,跳回时显示
    swift获取当前的Version
    swift回收键盘
    OC中常用的设计模式
    关于iOS多线程
    理解 : UDID、UUID、IDFA、IDFV
  • 原文地址:https://www.cnblogs.com/mol1995/p/9035721.html
Copyright © 2020-2023  润新知