Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Redirecting output from launchd?

I'm in the process of converting my existing cron tasks over to launchd and encountering a small-ish annoyance. I've gotten into the habit of writing cron commands like this, appending the output to a log file:

some_command and aparameter >> /the/full/path/to/the/logfile.txt

This just gives me a quick-and-dirty way to log activity from cron commands. When I do that in launchd, it doesn't go the expected location, but rather gets written out to the system log. Does launchd not support >> redirection like that or do I need to do it in some other way?

Mac OS X (10.5.5)

Posted on Nov 3, 2008 10:27 PM

Reply
Question marked as Best reply

Posted on Nov 3, 2008 10:38 PM

You can't shove an entire shell script in a launchd plist, you run one thing with one set of arguments--no piping, no expansion, no redirection. If you want to write to a log file then that code will have to live in whatever it is you want launchd to run.
8 replies

Nov 4, 2008 10:28 AM in response to Rick Anderson

If you want to write to a log file then that code will have to live in whatever it is you want launchd to run


Orange isn't actually correct here (sorry, Orange).

The solution actually lies in the .plist file for your script. launchd has many, many keys it supports one of which is:

StandardOutPath <string>
This optional key specifies what file should be used for data being sent
to stdout when using stdio(3).


Therefore your solution is to add a StandardOutPath key to your .plist

man launchd.plist lists all the keys that launchd uses.

Nov 6, 2008 6:50 PM in response to Rick Anderson

An excellent gui shell is lingon http://tuppis.com/lingon/
Apple Tutorial: Getting Started with launchd http://developer.apple.com/macosx/launchd.html
launchd in Depth: http://www.afp548.com/article.php?story=20050620071558293
launchd: One Programm to Rule Them All – Video presentation of launchd: http://video.google.com/videoplay?docid=1781045834610400422

I've looked around on the web for a good run-down of what it can do and some examples, but found very little. Seems like a great tool. I'm surprised there aren't more examples and tutorials out there showing what it can do.

Redirecting output from launchd?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.