Unity不会在C ++启动的控制台应用程序上显示“提示”消息

时间:2018-11-30 10:11:50

标签: c++ unity3d process system.diagnostics

在Unity项目中,我正在启动一个外部c ++简单控制台应用程序。

我的c ++控制台应用程序:

#include "pch.h"
#include <iostream>

int main(int argc, char *argv[], char *envp)
{
    // Display each command-line argument. 
    int count;
    std::cout << "\nCommand-line arguments:\n";
    for (count = 0; count < argc; count++)
        std::cout << "  argv[" << count << "]   "
        << argv[count] << "\n";

    std::cout << "Hello World!\n"; 
    getchar();
    return 0;
}

如您所见,该应用程序显示了传递的参数名称,如果我手动运行该应用程序,则其外观如下: enter image description here

但是当我从Unity启动同一应用程序时,控制台提示符为空。 这就是我从Unity启动c ++应用程序的方式:

using UnityEngine;
using System;
using System.IO;
using System.Diagnostics;

public class Launcher : MonoBehaviour {

    Process process = null;
    private void Start()
    {
        StartProcess();
    }

    void StartProcess()
    {
        try
        {
            process = new Process();
            process.EnableRaisingEvents = false;
            process.StartInfo.FileName = Application.dataPath + "/ConsoleTestApplication.exe";
            process.StartInfo.Arguments = "1 1 1"; //Without passing arguments, it also appears empty
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardInput = true;
            process.StartInfo.RedirectStandardError = true;
            process.Start();
            process.BeginOutputReadLine();

            UnityEngine.Debug.Log("Successfully launched app");
        }
        catch (Exception e)
        {
            UnityEngine.Debug.LogError("Unable to launch app: " + e.Message);
        }
    }
}

启动该应用程序,并出现控制台窗口,完全为空,对我做错了什么有任何想法吗?谢谢。

0 个答案:

没有答案