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();           

            }

        }

  • 相关阅读:
    购物车程序
    python学习第二节 数据类型、字符编码、文件处理
    while实现2-3+4-5+6...+100 的和
    给文件加权限
    查询数据插入新表格
    归档程序错误。在释放之前仅限于内部连接
    查看Linux环境变量
    查找文件命令
    ORACLE导入导出操作篇
    oracle中使用minus进行数据排除(类似SqlServer except函数)
  • 原文地址:https://www.cnblogs.com/mol1995/p/9035721.html
Copyright © 2011-2022 走看看