Problems using cmd with unity

2019-09-02 04:26发布

I'm trying to run command prompt from unity, my problem is that I can't find a way to fetch the result, here's my code

Process myProcess = new Process();
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.StartInfo.FileName = "C:\\Windows\\system32\\cmd.exe";
string path = "C:\\Users\\Sam\\Desktop\\Test\\rubik3Sticker.generator";
myProcess.StartInfo.Arguments = "call " + path;
myProcess.EnableRaisingEvents = true;
myProcess.Start();

until here it gives no exceptions, but unity crashes when I try to add this:

while(!myProcess.StandardOutput.EndOfStream)
    print(myProcess.StandardOutput.ReadLine());

any kind of help would be appreciated, thanks!

0条回答
登录 后发表回答