unity C#执行bat文件
unity的文件
普通的,调用bat目录即可
[MenuItem("Tools/GenerateBat普通的", priority = 101)]
public static void GenerateBat普通的()
{
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = "/C G:/gitHub/HYFClient/Excel_luban/normal.bat",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
};
Process process = new Process { StartInfo = startInfo };
process.Start();
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
AssetDatabase.Refresh();
Debug.LogFormat("普通的,结果会有--,{0}",output);
}
诡异的,这bat文件,非得cd到目录里,再调用下bat文件 不能直接使用全目录
[MenuItem("Tools/GenerateBat诡异的", priority = 102)]
public static void GenerateBat诡异的()
{
var cdPath = Application.dataPath.Replace("Assets", "Excel_luban");
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $"/C cd /D {cdPath} && gen.bat", //非得cd到某目录,再调用下bat文件 不能直接使用全目录
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
};
Process process = new Process { StartInfo = startInfo };
process.Start();
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
AssetDatabase.Refresh();
Debug.LogFormat("luban执行成功,数据lubanBytes,代码lubanCodes--,{0}",output);
}
原文地址:https://blog.csdn.net/SendSI/article/details/140531211
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!