![](/img/trans.png)
[英]Trying to run Python script with launchctl / launchd but it won't load. Exit status is 2
[英]Getting a status 78 launchctl when trying to run a python script with launchd
我正在尝试在 MAC OS X 上运行带有 launchd 的 python 脚本; 但是,脚本没有运行。 当我用launchctl检查状态码时,它是状态码78。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.chris.team-drive-table-contents</string>
<key>WorkingDirectory</key>
<string>cd ~/Coding\ Scripts/Google\ Apps\ Script/</string>
<key>ProgramArguments</key>
<array>
<string>python</string>
<string>team_drive_folder_tree.py</string>
</array>
<key>StartInterval</key>
<integer>60</integer>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
该脚本应每 60 秒运行一次,但它根本没有运行。
下面在我的系统上使用launchd调用python文件。 如果您可以在终端中使用类似 python3 myfile.py 的东西调用 python 文件,请为 python3.7 应用程序和文件输入正确的路径。 从您的示例中,这意味着您可以使用终端来调用“python team_drive_folder_tree.py”,因此您需要这两件事的路径并在下面更新我的代码。
在我的电脑上,我的 python3.7 版本恰好在我的 anaconda 用户目录中,所以我在下面的示例中引用了它。 其他一些注意事项:
文件名:com.local.pySched.plist
plist 在用户级别的 LaunchAgents 目录中
在您的 plist 标签之间:
<dict>
<key>Label</key>
<string>com.local.pySched</string>
<key>ProgramArguments</key>
<array>
<string>/Users/UsrName/anaconda3/bin/python3.7</string>
<string>/Users/UsrName/python_work/Schedule_Test.py</string>
</array>
<key>StartInterval</key>
<integer>60</integer>
<key>RunAtLoad</key>
<true/>
</dict>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.