简体   繁体   中英

Why are my launchd job's EnvironmentVariables not being set in OSX Yosemite

I have a plist like the following:

{
    "EnvironmentVariables" : {
        "PATH": "/bin:/usr/bin:/usr/local/bin",
        "TEST" : "some value"
    },
    "WorkingDirectory" : "/Users/me",
    "Program": "/usr/bin/printenv",
    "StandardErrorPath" : "myjob.log",
    "StandardOutPath" : "myjob.log",
    "Label" : "com.mydomain.MyJob",
    "RunAtLoad" : true
}

compiling it with:

plutil -convert binary1 -r myjob.plist.json -o myjob.plist

loading it with:

launchctl load myjob.plist

When I look at the results in myjob.log it doesn't contain any of the environment variables I defined in the plist. This is a problem for me because I can't seem to set the path to include things like /bin.

I haven't run this daemon in a while, but I believe it was functioning as expected on OSX Mountain Lion. The man page for launchd.plist implies this should work. Was there a change around the EnvironmentVariables key in Yosemite?

You should use launchctl to load the plist into launchd :

launchctl load -w myjob.plist

launchd manages processes, both for the system as a whole and for individual users. The primary and preferred interface to launchd is via the launchctl (1) tool which (among other options) allows the user or administrator to load and unload jobs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM