【问题标题】:Difficulties with launchd executing python scriptlaunchd 执行 python 脚本的困难
【发布时间】:2012-04-21 22:17:35
【问题描述】:

我正在尝试使用 launchd 每 10 分钟运行一次 python 脚本。使用 cron 很容易,但我已经尝试了几个小时来了解如何操作 launchd,但我一直没有成功。我正在使用位于/Users/turtle/bin/ 的python 版本。这是我的启动文件 (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

谁能帮帮我?感谢您的宝贵时间。

【问题讨论】:

    标签: macos launchd


    【解决方案1】:

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

    您必须使用 StartInterval :作业每 N

    启动一次
    <key>StartInterval</key>
    <integer>600</integer>
    

    【讨论】:

      【解决方案2】:
      launchctl load -w /Library/LaunchAgents/com.foobar
      

      这行得通吗?

      【讨论】:

      • 感谢您的帮助。不幸的是,我已经尝试了-w 标志,但它不起作用。
      • 如果我将 .plist 添加到它现在加载的文件名中,但 python 脚本仍然没有执行。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-11
      • 1970-01-01
      • 2013-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多