zoukankan      html  css  js  c++  java
  • ASP.Net 执行bat

    // Get the full file path
        string strFilePath = batPath;  //得到bat 文件全路径名

        // Create the ProcessInfo object
        System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("cmd.exe"); //启动cmd.exe
        psi.UseShellExecute = false;
        psi.RedirectStandardOutput = true;
        psi.RedirectStandardInput = true;
        psi.RedirectStandardError = true;
        psi.WorkingDirectory = "E:\\Work" //设定cmd.exe 的工作目录
        // Start the process
        System.Diagnostics.Process proc = System.Diagnostics.Process.Start(psi); //启动
        // Open the batch file for reading
        System.IO.StreamReader strm = System.IO.File.OpenText(strFilePath); //读bat 文件
        // Attach the in for writing
        System.IO.StreamWriter sIn = proc.StandardInput;
        // Write each line of the batch file to standard input
        while(strm.Peek() != -1)
        {
         sIn.WriteLine(strm.ReadLine());  //写入
        }
        strm.Close();
        // Exit CMD.EXE
        sIn.WriteLine("DEL " + strFilePath);   //执行完删除bat
        sIn.WriteLine("EXIT");
        // Close the process
        proc.Close();
        // Close the io Streams;
        sIn.Close();

  • 相关阅读:
    安卓9.0内测的背后,是上万App开发者半年来的适配优化
    错误记录:vue跟vue编译器版本不一致
    jspdf简单使用
    vue input添加回车触发
    vue watch bug记录
    SecureCRT通过拷贝配置文件登陆
    仿射变换
    opencv图像的旋转
    图像旋转的原理
    CvScalar
  • 原文地址:https://www.cnblogs.com/andycai/p/1763317.html
Copyright © 2011-2022 走看看