尽管文件存在并设置了工作目录,但C#Process.Start()无法启动

时间:2018-07-05 06:53:41

标签: c# python unity3d

Question update

我正在尝试在Unity中使用C#脚本来调用python程序。跟随这两个链接之后:

How do I run a Python script from C#?

Process.Start() not starting the .exe file (works when run manually)

我无法获得C#脚本来调用python程序。我知道这不是我的python脚本问题,因为我可以在终端中运行该程序而不会出现问题。

public class JsonStream : MonoBehaviour
{
    private string GetStream()
    {
        ProcessStartInfo start = new ProcessStartInfo();

        //none of the paths work, the uncommented variables return true when using File.Exists
        //while the commented variables return false
        start.FileName = "/Library/Frameworks/Python.framework/Versions/3.6/bin/python3";
        //start.FileName = "\"/Library/Frameworks/Python.framework/Versions/3.6/bin/python3\"";

        start.Arguments = Directory.GetCurrentDirectory() + "/Assets/googlesheetspyprojectbatch/stream.py";
        //start.Arguments = "\"" + Directory.GetCurrentDirectory() + "/Assets/googlesheetspyprojectbatch/stream.py" + "\"";

        start.WorkingDirectory = Directory.GetCurrentDirectory() + "/Assets/googlesheetspyprojectbatch";
        //start.WorkingDirectory = "\"" + Directory.GetCurrentDirectory() + "/Assets/googlesheetspyprojectbatch" + "\"";

        start.UseShellExecute = false;
        start.RedirectStandardOutput = true;
        start.ErrorDialog = true;
        start.RedirectStandardError = true;

        using (Process process = Process.Start(start))
        {
            using (StreamReader reader = process.StandardOutput)
            {
                string result = reader.ReadToEnd();
                return result;
            }
        }
    }

    public void DoEverythingStream()
    {
        UnityEngine.Debug.Log("Doing Stream");
        string json_text = GetStream();
        string[] games = json_text.Trim().Split('\n');
        foreach (string game in games)
        {
            UnityEngine.Debug.Log(game);
        }
    }
}

运行该程序不会引起任何错误,但也不会输出任何内容。有人对我的程序有什么想法吗?谢谢!

0 个答案:

没有答案