自取食用
using System.Diagnostics;
using UnityEditor;
using UnityEngine;
public static class ToolsManager
{
[MenuItem("Tools/外部Batch调用")]
private static void DoBatch()
{
string arg_1 = string.Empty;
string arg_2 = string.Empty;
string arg_n = string.Empty;
string args = arg_1 + " " + arg_2 + " " + arg_n;
Process process = CreateShellExProcess("外部batch名.bat", args, "batch路径");
process.WaitForExit();
process.Close();
// 以下为batch执行完毕的执行
// 为后续进程提供回调
}
/// <summary>
/// 调用外部Batch
/// </summary>
/// <param name="batName">batch名字,需要(.bat)</param>
/// <param name="args">传参(支持多参数,用空格隔开:"arg1 agr2")</param>
/// <param name="workingDir">batch的path</param>
/// <returns></returns>
public static Process CreateShellExProcess(string batName, string args = "", string workingDir = "")
{
var pStartInfo = new ProcessStartInfo(batName);
pStartInfo.Arguments = args;
pStartInfo.CreateNoWindow = false;
pStartInfo.UseShellExecute = true;
pStartInfo.RedirectStandardError = false;
pStartInfo.RedirectStandardInput = false;
pStartInfo.RedirectStandardOutput = false;
if (!string.IsNullOrEmpty(workingDir))
pStartInfo.WorkingDirectory = workingDir;
return Process.Start(pStartInfo);
}
}