当前位置:网站首页>【Unity】在Unity中使用C#执行外部文件,如.exe或者.bat
【Unity】在Unity中使用C#执行外部文件,如.exe或者.bat
2022-06-26 17:10:00 【T.D.C】
示例代码
var process = ExecuteFile(workPath, exePath);
if (process.Start())
{
Debug.Log(ReadToEnd(process.StandardOutput));
}
Debug.LogError(ReadToEnd(process.StandardError));
工具代码
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;
}
边栏推荐
- The texstudio official website cannot be opened
- [suggested collection] 11 online communities suitable for programmers
- What is the difference between digital collections and NFT
- Teach you to learn dapr - 1 The era of net developers
- Synchronized description of concurrency
- Discussion: the next generation of stable coins
- Detailed explanation of browser storage methods: the origin and difference of cookies, localstorage and sessionstorage
- 【uniapp】uniapp手机端使用uni.navigateBack失效问题解决
- Leetcode HOT100 (22--- bracket generation)
- Teach you to learn dapr - 8 binding
猜你喜欢

【万字总结】以终为始,详细分析高考志愿该怎么填

Daily record 2

Leetcode HOT100 (22--- bracket generation)

Teach you to learn dapr - 9 Observability

Ndroid development from introduction to mastery Chapter 2: view and ViewGroup

Platform management background and merchant menu resource management: merchant registration management design
![[C language] static modifies local variables](/img/bf/9084d2e924c3e1e244568562a83d74.jpg)
[C language] static modifies local variables

Teach you to learn dapr - 2 Must know concept

LeetCode——226. 翻转二叉树(BFS)

并发之线程安全
随机推荐
Programmer interview guide - self introduction
国信证券怎么开户?通过链接办理股票开户安全吗
Find all primes less than or equal to Lim, store them in AA array, and return the number of primes
Teach you to learn dapr - 2 Must know concept
Record the use process of fenics
MySql 导出数据库中的全部表索引
[ten thousand words summary] starting from the end, analyze in detail how to fill in the college entrance examination volunteers
Microservice architecture practice: user login and account switching design, order query design of the mall
【动态规划】剑指 Offer II 091. 粉刷房子
Leetcode daily [2022 - 02 - 16]
ACL 2022 | 基于神经标签搜索的零样本多语言抽取式文本摘要
Leetcode - 226. Retourner l'arbre binaire (bfs)
【uniapp】uniapp手机端使用uni.navigateBack失效问题解决
Teach you to learn dapr - 6 Publish subscription
Army chat -- registration of Registration Center
Interpretation of new plug-ins | how to enhance authentication capability with forward auth
Apache APIs IX has the risk of rewriting the x-real-ip header (cve-2022-24112)
Discover K8E: minimalist kubernetes distribution
Platform management background and merchant menu resource management: merchant registration management design
Convert the decimal positive integer m into the number in the forward K (2 < =k < =9) system and output it in bits