如何使用C#在OSX中正确运行chmod?
我和这里有同样的问题 我想通过Unity中的代码更改权限 我试过:如何使用C#在OSX中正确运行chmod?,c#,macos,unity3d,mono,chmod,C#,Macos,Unity3d,Mono,Chmod,我和这里有同样的问题 我想通过Unity中的代码更改权限 我试过: ProcessStartInfo startInfo = new ProcessStartInfo() { FileName = "chmod", Arguments = "+x " + "Game.app/Contents/MacOS/Game" }; Process proc = new Process() { StartInfo = start
ProcessStartInfo startInfo = new ProcessStartInfo()
{
FileName = "chmod",
Arguments = "+x " + "Game.app/Contents/MacOS/Game"
};
Process proc = new Process() { StartInfo = startInfo, };
proc.Start();
但是不起作用,有什么建议吗?我不确定,但可能您首先必须打开例如
bash
,然后使用-c
之类的函数将chmod
调用作为参数传递
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();
欢迎来到StackOverflow!您能否再进一步指定
不起作用
?有例外/错误吗?有什么事发生吗?您是否传递了正确的参数/路径?没有错误,但不起作用,我通过终端尝试了相同的命令,一切正常。您确定您的代码被调用/执行了吗?(断点和调试)是的,我确定。也许我添加了错误的参数?也许路径不正确?我不知道相对路径如何在iOS上实现统一。也许您必须指定startInfo.WorkingDirectory
仍然是相同的结果,我在Exited Delegateok中看到结果(ExitCode)1,所以至少我们知道该命令已执行,并且由于某些原因失败(退出代码1),也许您应该首先尝试运行“-c\”ls Game.app/Contents/MacOS/Game\”
并查看是否未找到相应的文件。我明白问题所在。我的游戏名称中有空格(Test game.app)。当我删除空格时,一切都很好。我替换了name Test\“game并开始工作。非常感谢您的时间