【Unity3d】在Unity3d中调用外部程序及批处理文件,写自动化编译脚本需要注意的地方

本文介绍了在Unity3d中如何调用外部应用程序,如notepad.exe,以及如何处理批处理文件和控制台输出的程序。通过具体的调用方法,帮助开发者编写自动化编译脚本时避免出现卡死问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

如果调用外部普通应用程序, 比如notepad.exe 这样调用

static public bool ExecuteProgram(string exeFilename, string workDir, string args)
{
	System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
	info.FileName = exeFilename;
	info.WorkingDirectory = workDir;
	info.RedirectStandardOutput = true;
	info.RedirectStandardError = true;
	info.Arguments = args;
	info.UseShellExecute = false;
	info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

	System.Diagnostics.Process task = null;

	bool rt = true;

	try
	{
		task = System.Diagnostics.Process.Start(info);
		if (task != null)
		{
			task.WaitForExit(10000);
		} 
		else
		{
			return false;
		}
	} 
	catch (Exception e)
	{
		Debug.LogError("Error: " + e.ToString());
		return false;
	} 
	finally
	{
		if (task != null && task.HasExited)
		{
			string output = task.StandardError.ReadToEnd();
			if (output.Length > 0)
			{
				Debug.LogError(output);
			}
			
		
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值