在Unity3d中调用外部程序及批处理文件
如果调用外部普通应用程序, 比如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();
}
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 > )
{
Debug.LogError(output);
} output = task.StandardOutput.ReadToEnd();
if (output.Length > )
{
Debug.Log("Error: " + output);
} rt = (task.ExitCode == );
}
} return rt;
}
如果需要调用Window的批处理文件BAT,
或者含有控制台输出的程序,
或者使用上面的方法卡死, 则使用下面的方法运行
static bool ExecuteProgram(string exeFilename, string workDir, string args)
{
System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
info.FileName = exeFilename;
info.WorkingDirectory = workDir;
info.UseShellExecute = true;
info.Arguments = args;
info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; System.Diagnostics.Process task = null;
bool rt = true;
try
{
Debug.Log("ExecuteProgram:" + args); task = System.Diagnostics.Process.Start(info);
if (task != null)
{
task.WaitForExit();
}
else
{
return false;
}
}
catch (Exception e)
{
Debug.LogError("ExecuteProgram:" + e.ToString());
return false;
}
finally
{
if (task != null && task.HasExited)
{
rt = (task.ExitCode == );
}
} return rt;
}
在Unity3d中调用外部程序及批处理文件的更多相关文章
- PowerShell中调用外部程序和进程操作命令例子
学习PowerShell,我们不指望通过C#编程去搞定所有事情,我们应该记住cmd.exe或者说批处理给我们留下的宝贵财富——通过调用外部程序去解决问题.调用了外部程序,势必就要对进程进行管理,这就是 ...
- JAVA中调用外部程序,并等待其退出(涉及Runtime和ProcessBuilder)
这段时间要写一个java调用外部程序的功能,踩了几个坑,这里分享一下. 首先用的是RunTime,调用代码如下: Process pro = Runtime.getRuntime().exec(&qu ...
- Unity3D中调用外接摄像头,并保存为图片文件
http://bbs.9ria.com/thread-170539-1-1.html 项目要求调用摄像头,并且把图像保存下来,上传到服务器. 这里有几个难点,调用摄像头是很简单的,unity已经提供好 ...
- C#使用Process类调用外部程序(转)
在程序开发中,一个程序经常需要去调用其他的程序,C#中Process类正好提供了这样的功能.它提供对本地和远程进程的访问并使您能够启动和停止本地系统进程.一.启动进程实例 Process myProc ...
- start 调用外部程序
批处理中调用外部程序的命令(该外部程序在新窗口中运行,批处理程序继续往下执行,不理会外部程序的运行状况),如果直接运行外部程序则必须等外部程序完成后才继续执行剩下的指令 例:start explore ...
- C#Process调用外部程序
前言 使用C#调用外部程序,一种是通过Process类,一种是通过命令行,本文主要说一下使用C#中的Process类调用外部程序的方式. 过程: 1. 创建Process对象 2. 配置启动选项(输入 ...
- Delphi - 调用外部程序并阻塞到外部程序中
Delphi 调用外部程序并阻塞到外部程序中 背景说明: 前段时间开发一个数据转换的系统,业务逻辑中说明数据需要压缩成.tar.gz格式. 我在Windows系统下采用,先生成批处理文件,然后调用Wi ...
- Unity3D中C#和js方法相互调用
通过查找资料,Unity3D中C#和js要相互调用彼此的方法,js文件必须放在"Standard Assets". "Pro Standard Assets" ...
- Unity3D中关于场景销毁时事件调用顺序的一点记录
先说一下我遇到的问题,我弄了一个对象池管理多个对象,对象池绑定在一个GameObject上,每个对象在OnBecameInvisible时会进行回收(即移出屏幕就回收),但是当场景切换或停止运行程序时 ...
随机推荐
- [转]Spring MVC 教程,快速入门,深入分析
原文地址:http://elf8848.iteye.com/blog/875830 目录 一.前言 二.spring mvc 核心类与接口 三.spring mvc 核心流程图 四.spring mv ...
- JAVA读取MongoDB中的二进制图片并在jsp中显示
http://blog.csdn.net/u012138706/article/details/52180665
- Ubuntu 14.04 编译 Android 4.2.2 for Tiny4412
. . . . . 在学校里是用 Redhat 6.4 编译的 Android 4.2.2 很顺利,把源码包拷贝到笔记本上的 Ubuntu 14.04 上再编译遭遇了各种坑,所以便有了这篇博客记录解决 ...
- Base64与MD5的区别
Base64和MD5都可用于做信息的简单加密,两者的简单差别如下: Base64 可逆性. 可以将图片等二进制文件转换为文本文件. 可以把非ASCII字符的数据转换成ASCII字符,避免不可见字符. ...
- C语言 · 排列数 · 排列式
蓝桥练习场上不断碰到类似的题,都是一个递归搜索的套路. 算法提高 排列数 时间限制:1.0s 内存限制:256.0MB 问题描述 0.1.2三个数字的全排列有六种,按照字母序排列如下 ...
- springcloud配置中心客户端配置遇到的坑
1. 出错信息如下: 在启动配置中心的客户端时,报以下错误信息: Caused by: java.lang.IllegalArgumentException: Could not resolve pl ...
- jstorm之于storm
关于流处理框架,在先前的文章汇总已经介绍过Strom,今天学习的是来自阿里的的流处理框架JStorm.简单的概述Storm就是:JStorm 比Storm更稳定,更强大,更快,Storm上跑的程序,一 ...
- 数组新增,修改json数据
1.向数组中添加json数据 var arr=[]; var json = {"name":"apple","color":"re ...
- 微信小程序——加入购物车弹层
对于网上商城,加入购物车是一个必备功能了.俺今天就来说下在微信小程序里如何造一个购物车弹层. 先上图: 主要用到的微信API:wx.createAnimation(OBJECT) 说下思路: 1.wx ...
- r语言 列出所有变量
你希望知道目前工作空间中存在哪些已定义的变量和函数. 解决方案 使用ls函数,或者使用ls.str函数了解每个变量更详细的信息. 讨论 ls函数可以显示当前工作空间中所有对象的名称:> x &l ...