当前位置:网站首页>[unity] use C in unity to execute external files, such as Exe or bat
[unity] use C in unity to execute external files, such as Exe or bat
2022-06-26 17:59:00 【T.D.C】
Sample code
var process = ExecuteFile(workPath, exePath);
if (process.Start())
{
Debug.Log(ReadToEnd(process.StandardOutput));
}
Debug.LogError(ReadToEnd(process.StandardError));
Tool code
public static string ReadToEnd(StreamReader reader)
{
var sbd = new StringBuilder();
while (true)
{
var readLine = reader.ReadLine();
if (readLine == null)
{
break;
}
sbd.AppendLine(readLine);
}
return sbd.ToString();
}
public static Process ExecuteFile(string workDir, string executeFile)
{
var process = new Process();
var startInfo = new ProcessStartInfo(executeFile)
{
WorkingDirectory = workDir,
CreateNoWindow = false,
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden,
RedirectStandardOutput = true,
RedirectStandardError = true,
StandardOutputEncoding = Encoding.GetEncoding("GB2312"),
StandardErrorEncoding = Encoding.GetEncoding("GB2312"),
};
process.StartInfo = startInfo;
return process;
}
边栏推荐
猜你喜欢

halcon之区域:多种区域(Region)特征(5)

行锁与隔离级别案例分析

Knapsack problem with dependency

非对称密码体制详解

MySql 导出数据库中的全部表索引

How sparksql returns a specific day of the week by date -dayofweek function

接水面试题

Number of solutions for knapsack problem

Troubleshooting ideas that can solve 80% of faults!

Analysis of deep security definition and encryption technology
随机推荐
sql中ROUND和TRUNCATE的区别(四舍五入还是截取小数点后几位)
in和exsits、count(*)查询优化
MySQL add column failed because there was data before, not null by default
Daily record 2
清华&商汤&上海AI&CUHK提出Siamese Image Modeling,兼具linear probing和密集预测性能!
RuntimeError: CUDA error: out of memory自己的解决方法(情况比较特殊估计对大部分人不适用)
wechat_ Solve the problem of page Jump and parameter transfer by navigator in wechat applet
Bayesian network explanation
让torch.cuda.is_available()从false变成true的一点经验
Leetcode daily [2022 - 02 - 16]
行锁分析和死锁
背包问题求方案数
Concurrent thread safety
transforms.RandomCrop()的输入只能是PIL image 不能是tensor
ZCMU--1367: Data Structure
Strength and appearance Coexist -- an exclusive interview with Liu Yu, a member of Apache pulsar PMC
IDEA收藏代码、快速打开favorites收藏窗口
14《MySQL 教程》INSERT 插入数据
Connected to surface test questions
RSA概念详解及工具推荐大全 - lmn