当前位置:网站首页>【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;
}
边栏推荐
- Sandboxed container: container or virtual machine
- Platform management background and merchant menu resource management: access control design of platform management background
- Count the number of words in a line of string and take it as the return value of the function
- Community ownership of NFT trading market is unstoppable
- 背包问题求方案数
- Microservice architecture practice: business management background and SSO design: SSO design
- Platform management background and merchant menu resource management: Design of platform management background data service
- 【动态规划】剑指 Offer II 091. 粉刷房子
- 玩转Linux,轻松安装配置MySQL
- Prometeus 2.34.0 新特性
猜你喜欢
Teach you to learn dapr - 1 The era of net developers
Apache APIs IX has the risk of rewriting the x-real-ip header (cve-2022-24112)
Necessary decorator mode for 3 years' work
Teach you to learn dapr - 3 Run the first with dapr Net program
Uncover the secret of Agora lipsync Technology: driving portraits to simulate human speech through real-time voice
玩轉Linux,輕松安裝配置MySQL
[matlab project practice] prediction of remaining service life of lithium ion battery based on convolutional neural network and bidirectional long short time (cnn-lstm) fusion
Wechat app mall, review products, upload commodity pictures, and score Commodity Services
Leetcode - 226. Retourner l'arbre binaire (bfs)
Leetcode 1170. Frequency of occurrence of the minimum letter of the comparison string (yes, solved)
随机推荐
MySql 导出数据库中的全部表索引
[latex bearer] use tables in \title (error \begin doesn't match its definition.)
Can Luo Yonghao succeed in entering the AR field this time?
She said she was tired! So tired! I want to change my career
[code Capriccio - dynamic planning] t583. Deleting two strings
[suggested collection] 11 online communities suitable for programmers
Prometeus 2.34.0 新特性
牛客网:设计LRU缓存结构 设计LFU缓存结构
Introduction to distributed cache / cache cluster
Live broadcast preview | how can programmers improve R & D efficiency? On the evening of June 21, the video number and station B will broadcast live at the same time. See you or leave!
【推荐系统学习】推荐系统架构
Troubleshooting ideas that can solve 80% of faults!
Uncover the secret of Agora lipsync Technology: driving portraits to simulate human speech through real-time voice
Leetcode topic [array] -283- move zero
Deployment and operation of mongodb partitioned cluster
Distributed Architecture Overview
Inspirational. In one year, from Xiaobai to entering the core Department of Alibaba, his counter attack
Calculate the sum of the main diagonals of the array
MySQL add column failed because there was data before, not null by default
ACL 2022 | zero sample multilingual extracted text summarization based on neural label search