0

I want to write a python script to call 'brew update' daily in my Mac. The below is the python script and launch plist.

#!/usr/local/bin/python import subprocess # update homebrew and check outdated package subprocess.call(["brew", "update"]) subprocess.call(["brew", "outdated"]) subprocess.call(["brew", "doctor"]) 

.plist

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>chancy.daily</string> <key>ProgramArguments</key> <array> <string>/usr/local/bin/python</string> <string>/Users/wuchangxi/Workspace/scripts/jobs/daily.py</string> </array> <key>StandardErrorPath</key> <string>/usr/local/var/log/chancy.daily.log</string> <key>StandardOutputPath</key> <string>/usr/local/var/log/chancy.daily.log</string> <key>StartCalendarInterval</key> <dict> <key>Minute</key> <integer>42</integer> <key>Hour</key> <integer>12</integer> </dict> </dict> </plist> 

When i run using the launchd load the plist file, there is the same error as below:

Traceback (most recent call last): File "/Users/wuchangxi/Workspace/scripts/jobs/daily.py", line 5, in <module> subprocess.call(["brew", "update"]) File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 522, in call return Popen(*popenargs, **kwargs).wait() File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__ errread, errwrite) File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory 

If run the python script directly in shell, it works well. But when call in the .plist, there is No such file error.

1 Answer 1

1

I suspect that this is because the launchd environment is not setting up a PATH that matches what you would have in your own shell

You might need to pass the absolute path to the brew binary, or setup an Environment section in your plist that contains the PATH you want to use

Sign up to request clarification or add additional context in comments.

2 Comments

Do you know how to set the Environment section to contains the PATH?
I personally do not, but Google does: apple.stackexchange.com/questions/106355/… or apple.stackexchange.com/questions/64916/… talk about it in some detail

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.