zoukankan      html  css  js  c++  java
  • 用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();           

            }

        }

  • 相关阅读:
    测试平台系列(56) JSON深层次对比方案
    测试平台系列(57) 美化代码编辑器
    测试平台系列(54) 数据库表接口适配前端页面(下)
    测试平台系列(55) 引入AceEditor(代码编辑器)
    测试平台系列(52) 改造异步数据库连接方案
    测试平台系列(53) 数据库表接口适配前端页面(上)
    二叉树
    OCP 063中文考试题库(cuug内部资料)第34题
    OCP 063中文考试题库(cuug内部资料)第33题
    OCP 063中文考试题库(cuug内部资料)第32题
  • 原文地址:https://www.cnblogs.com/mol1995/p/9035721.html
Copyright © 2011-2022 走看看