I have a launchd script where the command I'm trying to run is erroring (apparently that's not a word, it is now), complaining of improper usage.
The specific error I'm getting is the command's usage text dumped to the system log. From this I infer the other info (path to the command, timing etc.) in the plist is being parsed correctly, just not the command's options.
After the command usage I have one last line:
18/11/2013 09:30:00.101 com.apple.launchd.peruser.501: (fake.lable.seti[33833]) Exited with code: 1
But that just means "I exited with an error".
I know launchd splits the command from its options and in the man page tells you about ProgramArguments: "...Please note: many people are confused by this key. Please read execvp(3) very carefully!.."
Well I read execvp(3) and I'm none the wiser, so I'm asking you lovely lot.
Normally, running the command from the terminal it'd look like this:
/Library/Application\ Support/BOINC\ Data/boinccmd --host localhost --passwd gobbledygook --project http://setiathome.berkeley.edu/ update
This works a treat.
And this is how I've split it in the Program/ProgramArguments section of my LaunchAgent plist:
<key>Program</key>
<string>/Library/Application Support/BOINC Data/boinccmd</string>
<key>ProgramArguments</key>
<array>
<string>--host localhost</string>
<string>--passwd gobbledygook</string>
<string>--project http://setiathome.berkeley.edu/ update</string>
</array>
(for the record, I originally had the path to boinccmd \escaped out, but that doesn't work, launchd escapes spaces in the path for you)
I've tried splitting the arguments down further:
<key>Program</key>
<string>/Library/Application Support/BOINC Data/boinccmd</string>
<key>ProgramArguments</key>
<array>
<string>--host</string>
<string>localhost</string>
<string>--passwd</string>
<string>gobbledygook</string>
<string>--project</string>
<string>http://setiathome.berkeley.edu/</string>
<string>update</string>
</array>
But that didn't seem to work either.
As ever, I'm very sure I'm missing something so simple.
Thanks.
ANSWER:
The first line of ProgramArguments needs to be the path to the program. This is what was tripping me up and indeed what was probably meant by the "...Please read very carefully!.." comment :) I also found I had to split the arguments down to their component parts. When I had all that in place the whole thing works a charm. Thank you very much.
<key>Program</key>
<string>/Library/Application Support/BOINC Data/boinccmd</string>
<key>ProgramArguments</key>
<array>
<string>/Library/Application Support/BOINC Data/boinccmd</string>
<string>--host</string>
<string>localhost</string>
<string>--passwd</string>
<string>gobbledygook</string>
<string>--project</string>
<string>http://setiathome.berkeley.edu/</string>
<string>update</string>
</array>
A final edit to say for an easy to understand explanation as to WHY this should be, see SirPavlova's explanation.
~W
<string>--host localhost</string>
will definitely not work. Remember, when you write a command line to a shell, it has no idea what's part of an option and what's a regular argument — it just splits on spaces before passing the arguments to the program being run. Also, it might help if you were to show the exact error thatboinccmd
is reporting.