-1

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?

derHugo
  • 83,094
  • 9
  • 75
  • 115
eugen
  • 1
  • 2
  • 2
    Welcome to StackOverflow! could you specify `doesn't work` a little further? Any exceptions/errors? Does anything happen at all? Do you pass the correct arguments/path? – derHugo Jul 15 '19 at 14:11
  • no errors but not work, I tried the same commands via terminal and everything works – eugen Jul 15 '19 at 14:15
  • are you sure your code is called/executed at all? (breakpoints & debugging) – derHugo Jul 15 '19 at 14:18
  • yeah, I'm sure. Maybe I added the wrong arguments? – eugen Jul 15 '19 at 14:22
  • maybe the path isn't correct? I don't know how the relative paths work for Unity on iOS. Maybe you will have to specifiy the `startInfo.WorkingDirectory` – derHugo Jul 15 '19 at 14:40
  • I testing standalone mac build not iOS, testing different paths right now – eugen Jul 15 '19 at 14:42

1 Answers1

0

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();
derHugo
  • 83,094
  • 9
  • 75
  • 115
  • still the same result, – eugen Jul 15 '19 at 15:11
  • I see result (ExitCode) 1 in Exited Delegate – eugen Jul 15 '19 at 15:12
  • ok so atleast we know the command is executed and for some reason fails (exit code 1) maybe first you should try to run `"-c \"ls Game.app/Contents/MacOS/Game\""` and see if maybe the according file is not found – derHugo Jul 15 '19 at 15:15
  • ah, sec. I see the problem. my game has space in the name (Test Game.app) everything works great when I removed space – eugen Jul 15 '19 at 15:21
  • I replaced name Test\" Game and works. thanks a lot for your time – eugen Jul 15 '19 at 15:23