unity3d:process 进程调用C#控制台程序,并获得输出。传入参数有空格要加""

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/luoyikun/article/details/88963510
public static Process StartProcess(string fileName,string args)
    {
        try
        {
            fileName = "\"" + fileName + "\"";
            //args = "\"" + args + "\"";
            Process myProcess = new Process();
            ProcessStartInfo startInfo = new ProcessStartInfo(fileName, args);
            startInfo.CreateNoWindow = true;
            startInfo.RedirectStandardInput = true;
            startInfo.UseShellExecute = false;
            startInfo.RedirectStandardOutput = true;
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            myProcess.StartInfo = startInfo;
            return myProcess;
        }
        catch (Exception ex)
        {
            UnityEngine.Debug.Log("出错原因:" + ex.Message);
        }
        return null;
}

使用示例:

string param = "\"" + "立羽" + "\"";
        Process pro = PublicFunc.StartProcess(Application.streamingAssetsPath + "/PngAddText/TextToPng.exe",param);
        pro.Start();

        string fingerprint = pro.StandardOutput.ReadLine();
        UnityEngine.Debug.Log(fingerprint);
        pro.WaitForExit();
        pro.Close();

猜你喜欢

转载自blog.csdn.net/luoyikun/article/details/88963510