0

When I try to load some process behalf of another user I receive next error:

sudo: someusername: command not found
system result: 256

Please note that I run it from the process which is running under root.

Here is a code how I do:

        NSString *command = @"sudo someusername /bin/launchctl load -S Aqua /Library/LaunchAgents/com.agent.someagent.plist";
        int result = system([command UTF8String]);
        NSLog(@"system result: %d", result);
Serge
  • 2,031
  • 3
  • 33
  • 56
  • Shouldn't that be `sudo -u someusername ...`? – trojanfoe Jul 15 '14 at 14:23
  • When I user the command described above in terminal it is running correctly. Anyway when I set -u, I receive another error: launch_msg(): Socket is not connected – Serge Jul 15 '14 at 14:27
  • So the `-u` flag is correct then. – trojanfoe Jul 15 '14 at 14:27
  • Not really. I need to run the command above programatically because it works in terminal. – Serge Jul 15 '14 at 14:31
  • That exact command can't work in the terminal. The syntax is wrong. – nobody Jul 15 '14 at 14:32
  • You used to think `-u` is important (http://stackoverflow.com/questions/24137738/launching-command-using-nstask-returns-error) and the error you are getting now looks `launchd`-related which shows that you are invoking it at least. – trojanfoe Jul 15 '14 at 14:34

0 Answers0