Unity3D 调用外部batch

自取食用

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);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值