且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

"hello world"启动的plist不起作用

更新时间:2023-08-24 11:40:22

您要的是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>