首页 > 解决方案 > 如何使用 C# 在 OSX 中正确运行 chmod?

问题描述

我和这里有同样的问题How run chmod in OSX with C#

我想通过我尝试过的 Unity 中的代码更改权限:

ProcessStartInfo startInfo = new ProcessStartInfo() 
{
    FileName = "chmod",
    Arguments = "+x " + "Game.app/Contents/MacOS/Game"                              
};

Process proc = new Process() { StartInfo = startInfo, };
proc.Start();

但不起作用,有什么建议吗?

标签: c#macosunity3dmonochmod

解决方案


我不确定,但也许你首先必须打开例如bash,然后使用类似的东西将chmod调用作为参数传递-c

ProcessStartInfo startInfo = new ProcessStartInfo() 
{
    FileName = "/bin/bash",
    Arguments = "-c \" chmod +x  Game.app/Contents/MacOS/Game\" ",

    CreateNoWindow = true
};

Process proc = new Process() { StartInfo = startInfo, };
proc.Start();

仍然假设当然路径是正确的。

并且也许还添加一些回调,例如

proc.ErrorDataReceived += (sender, e) =>
{
    UnityEngine.Debug.LogError(e.Data);
};
proc.OutputDataReceived += (sender, e) =>
{
    UnityEngine.Debug.Log(e.Data);
};
proc.Exited += (sender, e) =>
{
    UnityEngine.Debug.Log(e.ToString());
};

proc.Start();

推荐阅读