分成2个步骤,首先生成一个bat文件,然后调用批处理文件

1.生成.bat文件

入参为文件的内容,filePath为绝对路径,且需要扩展名(这个方法不局限于生成.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();
}
}

2.调用.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());
}

BAT文件的调用的更多相关文章

  1. bat文件中调用传参的问题

    https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-lin ...

  2. Unity打开外部程序exe/Bat文件方案

    Unity调用外部程序/Bat文件 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- ...

  3. 在Salesforce中通过编写C#程序调用dataloadercliq的bat文件取触发调用data loader来批量处理数据

    通过这篇文章 http://www.cnblogs.com/mingmingruyuedlut/p/3413903.html 我们已经知道了Data Loader可以对Salesforce的Objec ...

  4. .bat文件调用java类的main方法

    此处记录一个小例子,备用,说不定哪天写小工具时会用到. @echo on set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_43 set classpath=. ...

  5. as3调用外部应用程序 as调用外部exe文件as3调用bat文件 未测试

    private function callTest(event: Event): void{callExe("d:/a.exe");callBat("d:/a.bat&q ...

  6. [Jmeter]通过批处理调用java,java从CSV动态读取登录的用户名和密码,并将其作为参数组合成字符串,写入外部.bat文件,然后通过Java执行这个外部批处理文件

    问题1:怎样通过批处理调用java代码? 问题2:怎样通过java从CSV文件获取到用户名和密码存入变量? 问题3:怎样将获取到的用户名和密码组合成字符串,写入外部批处理文件? 问题4:怎样在批处理文 ...

  7. bat文件【java调用】

    Runtime.getRuntime().exec("cmd /c del c:\\a.doc");   //Runtime.getRuntime().exec("not ...

  8. 用一个bat文件调用另外两个bat文件,当1.bat执行完后再执行2.bat

    用一个bat文件调用另外两个bat文件,当1.bat执行完后再执行2.bat 摘自:https://zhidao.baidu.com/question/492732911.html @echo off ...

  9. .bat 文件调用python脚本

    1.将clearlog.py 脚本放在指定目录 比如 我放在 C:\Users\Administrator\Desktop 上 也就是桌面上 2.创建一个.bat 位后缀名的脚本 3.写入如下脚本 @ ...

随机推荐

  1. 【转】Lombok介绍、使用方法和总结

    链接:http://www.yuanrengu.com/index.php/20180324.html 1 Lombok背景介绍 官方介绍如下: Project Lombok makes java a ...

  2. kafka示例

    1. 引入依赖 <dependency> <groupId>org.apache.kafka</groupId> <artifactId>kafka-c ...

  3. win10无法安装软件解决

    https://www.windowscentral.com/how-fix-network-resource-unavailable-install-error-windows-10

  4. Atcoder Grand Contest 036 D - Negative Cycle

    Atcoder Grand Contest 036 D - Negative Cycle 解题思路 在某些情况下,给一张图加或删一些边要使图合法的题目要考虑到最短路的差分约束系统.这一题看似和最短路没 ...

  5. Harbor 企业级私有仓库 Ubuntu16.04 搭建及使用

    一.Harbor简介 1.1.什么是Harbor 几个VMware中国的人搞了一个容器镜像仓库.Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器. 1.2.Harbor架 ...

  6. JPA、Hibernate、Spring data jpa之间的关系,以及和springboot的整合

    什么么是JPA? 全称Java Persistence API,可以通过注解或者XML描述[对象-关系表]之间的映射关系,并将实体对象持久化到数据库中. 为我们提供了: 1)ORM映射元数据:JPA支 ...

  7. Java开发环境搭建(一)

    一.JDK与JRE JDK:Java Development Kit,Java开发工具包,是给开发人员使用的,其中包含了Java的开发工具,如java.javac.jar等命令,同时也包含了JRE. ...

  8. windows cmd下列出当前目录下的所有文件

    使用的命令是dir 如,列出当前目录下的目录及文件名到1.txt: dir /b >1.txt 只列出某类文件 dir *.txt  /b >1.txt

  9. console.log()、console.info()、console.debug()的区别

    onsole.log().console.info().console.debug()的作用都是在浏览器控制台打印信息的. 使用最多的是console.log().console.info()和con ...

  10. vue计算属性的使用

    props:['name'],//接收父组件的数据 computed:{//当数据发生改变时,会自动去计算 zojia:function(){ //zojia是自己声明的函数 let a = null ...