启动执行python脚本的困难

时间:2012-04-21 22:17:35

标签: macos launchd

我试图使用launchd每10分钟运行一次python脚本。对于cron来说这很容易,但我已经尝试了几个小时来了解如何操作launchd并且我没有成功。我正在使用位于/Users/turtle/bin/的python版本。这是我的launchd文件(com.foobar)的样子:

<?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>com.foobar</string>
        <key>ProgramArguments</key>
        <array>
            <string>/Users/turtle/bin/python</string>
            <string>/Users/turtle/code/baz.py</string>
        </array>
        <key>StartCalendarInterval</key>
        <dict>
            <key>Minute</key>
            <integer>10</integer>
        </dict>
    </dict>
</plist>

当我跑步时:

launchctl load /Library/LaunchAgents/com.foobar

我明白了:

launchctl: Couldn't stat("/Library/LaunchAgents/com.foobar"): No such file or directory nothing found to load

任何人都可以帮助我吗?谢谢你的时间。

2 个答案:

答案 0 :(得分:1)

使用键分钟

StartCalendarInterval :脚本在每小时的第10分钟运行。

您必须每隔N 秒启动 StartInterval :作业

<key>StartInterval</key>
<integer>600</integer>

答案 1 :(得分:0)

launchctl load -w /Library/LaunchAgents/com.foobar

这有用吗?