"hello world"启动的plist不起作用 [英] "hello world" launchd plist not working

查看:101
本文介绍了"hello world"启动的plist不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在〜/Library/LaunchAgents中具有以下plist文件:

I have the following plist file at ~/Library/LaunchAgents:

<?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.yogapo.test_launchd</string>

    <key>Program</key>
    <string>. /Users/luke/dev/data_yogapo/script/test_launchd.sh</string>

    <key>StartInterval</key>
    <integer>10</integer>

    <key>RunAtLoad</key>
    <true/>
  </dict>
</plist>

test_launchd.sh文件包含以下内容:

And the test_launchd.sh file is contains the following:

#! /bin/bash 

echo "hello world from test_launchd.sh" >> /Users/luke/dev/data_yogapo/log/development.log

当我使用
手动运行test_launchd.sh时 . /Users/luke/dev/data_yogapo/script/test_launchd.sh 结果符合预期:该行显示在development.log

When I run test_launchd.sh manually with
. /Users/luke/dev/data_yogapo/script/test_launchd.sh the results are as expected: the line appears at the end of development.log

但是当我加载这个plist文件时,什么也没发生:

But when I load up this plist file, nothing happens:

$ cd ~/Library/LaunchAgents
$ launchctl load com.yogapo.test_launchd.plist
$ launchctl list | grep yogapo
  -       1       com.yogapo.test_launchd

我已经尝试过使用RunAtLoad键,也可以不使用RunAtLoad键.我在SO以及互联网上的其他地方都看过其他答案.我遵循了教程,但没有任何反应.任何帮助,不胜感激-谢谢!

I've tried this with and without the RunAtLoad key. I've looked at other answers here on SO as well as elsewhere on the internet. I've followed tutorials, and there's simply nothing happening. Any help much appreciated - thanks!

推荐答案

您要的是launchd运行名为"progam"的程序

You are asking launchd to run progam called

". /Users/luke/dev/data_yogapo/script/test_launchd.sh"

它将把Program键的整个值作为execvp的第一个参数(请参阅

It will take the entire value of the Program key as the first argument to execvp(see man execvp(3) for more details)

如果要检查system日志,则会看到类似以下内容的内容:

If you were to examine the system log, you would see something like:

5月22日21:17:38破坏了com.apple.launchd.peruser.501 [202] (com.yogapo.test_launchd [32986]):posix_spawn(. /Users/luke/dev/data_yogapo/script/test_launchd.sh,...):否这样 文件或目录5月22日21:17:38已删除 com.apple.launchd.peruser.501 [202](com.yogapo.test_launchd [32986]): 退出,退出代码:1

May 22 21:17:38 dented com.apple.launchd.peruser.501[202] (com.yogapo.test_launchd[32986]): posix_spawn(". /Users/luke/dev/data_yogapo/script/test_launchd.sh", ...): No such file or directory May 22 21:17:38 dented com.apple.launchd.peruser.501[202] (com.yogapo.test_launchd[32986]): Exited with exit code: 1

launchd不是shell.但是,它可以解释哈希爆炸字符序列,以标识用于解释脚本的程序.因此,只需将脚本指定为要运行的程序:

launchd is not a shell. However, it can interpret hash-bang character sequences to identify which program to use to interpret your script. Therefore, simply specify your script as the program to run:

<key>Program</key>
<string>/Users/luke/dev/data_yogapo/script/test_launchd.sh</string>

注意:如果需要将参数传递给脚本,请改用ProgramArguments键,并将整个命令行放在此处.例如:

Note: Should you need to pass arguments to your script, use the ProgramArguments key instead and put the whole command line there. For example:

<key>ProgramArguments</key>
<string>/Users/luke/dev/data_yogapo/script/test_launchd.sh arg1 arg2 arg3</string>

这篇关于"hello world"启动的plist不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆