Wednesday, July 27, 2022

[SOLVED] How to run properly chmod in OSX with C#?

Issue

I have the same problem as here How run chmod in OSX with C#

I would like to change permission via code in Unity I tried :

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

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

but doesn't work, any advices?


Solution

I'm not sure but maybe you first have to open e.g. bash and then pass in the chmod call as parameter using -c something like

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();

still assuming ofcourse the path is correct.

and maybe also add some callbacks like

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();


Answered By - derHugo
Answer Checked By - Mary Flores (WPSolving Volunteer)