zoukankan      html  css  js  c++  java
  • 利用C#生成、执行bat文件

    生成bat文件

    public void writeBATFile(string fileContent)
            {string filePath = "D:\test\testChange.bat";
                if (!File.Exists(filePath))
                {
                    FileStream fs1 = new FileStream(filePath, FileMode.Create, FileAccess.Write);//创建写入文件
                    StreamWriter sw = new StreamWriter(fs1);
                    sw.WriteLine(fileContent);//开始写入值
                    sw.Close();
                    fs1.Close();
                }
                else
                {
                    FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Write);
                    StreamWriter sr = new StreamWriter(fs);
                    sr.WriteLine(fileContent);//开始写入值
                    sr.Close();
                    fs.Close();
                }
            }
    

      执行 bat

    using System.Diagnostics;
    
    Process proc = null;
                try
                {
                    string targetDir = string.Format(@"D:BizMap");//this is where testChange.bat lies
                    proc = new Process();
                    proc.StartInfo.WorkingDirectory = targetDir;
                    proc.StartInfo.FileName = "testChange.bat";
                    proc.StartInfo.Arguments = string.Format("10");//this is argument
                    //proc.StartInfo.CreateNoWindow = true;
                    //proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;//这里设置DOS窗口不显示,经实践可行
                    proc.Start();
                    proc.WaitForExit();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception Occurred :{0},{1}", ex.Message, ex.StackTrace.ToString());
                }
    

      

  • 相关阅读:
    JQuery对象与Dom对象相互转化
    JQuery练习demo2
    ExtJs简单的登录界面制作
    JQuery练习demo1(隔行变色)
    html标签label的for属性
    Android环境搭建(Windows)
    JQuery表格操作练习
    ExtJs简单动态ComboBox
    Asp.Net母版页的使用
    SQL经典语句大全
  • 原文地址:https://www.cnblogs.com/bysx/p/9492918.html
Copyright © 2011-2022 走看看