我怎样才能到OSX的launchd plist中管道输出参数添加到日志文件? [英] How can I add arguments to OSX launchd plist to pipe output to a log file?

查看:168
本文介绍了我怎样才能到OSX的launchd plist中管道输出参数添加到日志文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了这个许多不同的变化,但只是无法得到它的工作。

I have tried many different variation on this but just can't get it to work.

我有一个plist文件:

I have a plist file:

<?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.ilium007.handbrake</string>
        <key>ProgramArguments</key>
        <array>
                <string>/bin/bash</string>
                <string>/Users/ilium007/support/scripts/handbrake/handbrake.sh &gt;&gt; /Users/ilium007/support/scripts/handbrake/logs/handbrake_encode.log</string>
                <!--<string>&gt;&gt;</string>-->
                <!--<string>/Users/ilium007/support/scripts/handbrake/logs/handbrake_encode.log</string>-->
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>StartInterval</key>
        <integer>60</integer>
</dict>
</plist>

请注意在那里的说明。

我想从handbrake.sh脚本输出管道到一个日志文件,并尝试这样做,但不断收到SYSTEM.LOG中的一个没有这样的文件的错误在OSX。

I want to pipe output from the handbrake.sh script to a log file and have tried to do so but keep getting A "no such file" error in system.log on OSX.

Nov  3 18:03:54 macmini com.ilium007.handbrake[15348]: /bin/bash: /Users/ilium007/support/scripts/handbrake/handbrake.sh >> /Users/ilium007/support/scripts/handbrake/logs/handbrake_encode.log: No such file or directory Nov  3 18:03:54 macmini com.apple.launchd.peruser.501[162] (com.ilium007.handbrake[15348]): Exited with code: 127

如果我改变的plist到下面,运行,但我没有得到任何记录,所以我认为它只是运行的第一个参数:

If I change the plist to the following, it runs but I get no log so I assume it is only running the first argument:

<?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.ilium007.handbrake</string>
        <key>ProgramArguments</key>
        <array>
                <string>/bin/bash</string>
                <string>/Users/ilium007/support/scripts/handbrake/handbrake.sh</string>
                <string>&gt;&gt;</string>
                <string>/Users/ilium007/support/scripts/handbrake/logs/handbrake_encode.log</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>StartInterval</key>
        <integer>60</integer>
</dict>
</plist>

这是我想通过的launchd运行的命令是:

The command that I would like to run via launchd is:

/Users/ilium007/support/scripts/handbrake/handbrake.sh >> /Users/ilium007/support/scripts/handbrake/logs/handbrake_encode.log

什么事也没出现在日志文件中。但是,如果我从终端运行这个命令我得到的日志中的内容。任何帮助将是AP preciated。

Nothing ever appears in the log file. But if I run that command from the terminal I get content in the log. Any help would be appreciated.

推荐答案

&GT;&GT; 是一个外壳经营者,不是一个程序参数,launchd会不及格通过一个shell命令它(除非你强迫它,如@劳里的答案)。但是launchd中确实有重定向标准输出了自己的选择:

>> is a shell operator, not a program argument, and launchd doesn't pass its commands through a shell (unless you force it, as in @Lauri's answer). But launchd does have its own option for redirecting stdout:

<key>StandardOutPath</key>
<string>/Users/ilium007/support/scripts/handbrake/logs/handbrake_encode.log</string>

请注意,它会自动追加(相当于&GT;&GT; ,而不是&GT; )。您也可以重定向与 StandardErrorPath 键标准错误。有一件事你不能做的是使用(在〜/支持/脚本/手刹/日志/ handbrake_en code.log) - 这,又是一个外壳有可launchd会不会效仿。

Note that it automatically appends (equivalent to >>, not >). You can also redirect stderr with the StandardErrorPath key. One thing you cannot do is use ~ (as in ~/support/scripts/handbrake/logs/handbrake_encode.log) -- that, again, is a shell feature that launchd doesn't emulate.

这篇关于我怎样才能到OSX的launchd plist中管道输出参数添加到日志文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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