Loading

C# Bat批处理文件创建、执行

//执行bat批处理
public static void Main()
{
	ProcessStartInfo myBat = new ProcessStartInfo()
	{
		FileName = "D:\\temp\\myBat.bat",
		WorkingDirectory = Directory.GetCurrentDirectory(),
		UseShellExecute = false
	};
	Process.Start(myBat).WaitForExit();
}
//批处理文件创建
public void WriteBatFile(string filePath, string fileContent)
{
	File.Delete(filePath);
	FileStream fs1 = new FileStream(filePath, FileMode.Create, FileAccess.Write);//创建写入文件
	StreamWriter sw = new StreamWriter(fs1);
	sw.WriteLine(fileContent);//开始写入值
	sw.Close();
	fs1.Close();
}
posted @ 2021-09-22 17:36  Stay627  阅读(555)  评论(0编辑  收藏  举报