栏目分类:
子分类:
返回
终身学习网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
终身学习网 > IT > 软件开发 > 后端开发 > .Net

c#打包工具支持bat

.Net 更新时间:发布时间: 百科书网 趣学号

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

}

转载请注明:文章转载自 www.051e.com
本文地址:http://www.051e.com/it/955628.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 ©2023-2025 051e.com

ICP备案号:京ICP备12030808号