本文介绍了使用Unity3D的C#system.process stdin/stdout处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个星期前,我问了一个非常类似的问题,但我仍然设法找到答案.

I asked a very similar question one week ago and I still try to find an answer.

我建立了一个完整的新Unity3D项目,在其中放置了一个对象,创建了一个C#脚本,并将以下代码放入了Start()方法中.

I setup a complete new Unity3D project, put an object in it, create a C# script and put the following code in the Start() method.

void Start() {

    Process myProcess = new Process();

    myProcess.StartInfo.FileName = "gnome-terminal";
    myProcess.StartInfo.UseShellExecute = false;
    myProcess.StartInfo.RedirectStandardInput = true;
    myProcess.StartInfo.RedirectStandardOutput = true;
    //myProcess.StartInfo.CreateNoWindow = true; for testing
    myProcess.Start();
    //Thread.Sleep(6000); somebody suggest wait some time, but it make no difference
    myProcess.StandardInput.WriteLine("sensible-browser");

}

我为Linux Ubuntu系统构建项目并执行它.出现一个新的终端,仅此而已.通常,现在应该打开浏览器,但不能打开.

I build the project for my Linux Ubuntu system and execute it. A new terminal appears and that's it. Normally, now the browser should be open but it doesn't.

那只是我的测试程序.在我的起源中,我必须从stdin/stdout中读取/写入.

That's only my test program. In my origin one I have to read/write from/into the stdin/stdout.

我非常绝望,希望你们中的任何人都可以帮助我

I'm fully desperate and hopefully anyone of you can help me

谢谢

推荐答案

使用bash代替gnome-terminal.

Process myProcess = new Process();
myProcess.StartInfo.FileName = "bash";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardInput = true;
myProcess.Start();
myProcess.StandardInput.WriteLine("sensible-browser");
myProcess.StandardInput.Close();

这篇关于使用Unity3D的C#system.process stdin/stdout处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 19:17