我一直在构建一个 golang app带有系统托盘 GUI。我要 launchctl
每当我登录时运行我的程序。程序编译并运行没有任何错误,但是,当 launchctl
运行它,我看到这个:Service exited with abnormal code: 78
.也许这与权利有关。
plist
文件和二进制文件。还是报错78
. plist
的权限文件和二进制文件到 根并运行 sudo launchctl
.我仍然看到错误 78
. /var/log/system.log
有这个错误:14:46:00 Macchiato com.apple.xpc.launchd[1] (com.test.test[519]): Service could not initialize: 18A391: xpcproxy + 11291 [1534][8188841E-6D08-3F80-8488-9B5D7462BACB]: 0xd
14:46:00 Macchiato com.apple.xpc.launchd[1] (com.test.test[519]): Service exited with abnormal code: 78
14:46:00 Macchiato com.apple.xpc.launchd[1] (com.test.test): Service only ran for 0 seconds. Pushing respawn out by 10 seconds.
plist
文件本身是:<?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.test.test</string>
<key>ProgramArguments</key>
<array>
<string>/Users/test-user/test/test</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>ProcessType</key>
<string>Standard</string>
<key>KeepAlive</key>
<true/>
<key>StandardErrorPath</key>
<string>/var/log/test-err.log</string>
<key>StandardOutPath</key>
<string>/var/log/test-out.log</string>
</dict>
</plist>
错误日志为空。
当我运行 binary手动,应用程序的图标会出现在系统托盘上,正如预期的那样。
有一个有趣的时刻——如果我手动输入
launchctl load -w com.test.test.plist
, 应用程序运行良好 - 直到重新启动。重启后,launchctl
抛出 78
错误。为什么会这样?
最佳答案
我想我解决了我自己的问题。似乎是错误 78
当我使用时来
<key>StandardErrorPath</key>
<string>/var/log/test-err.log</string>
<key>StandardOutPath</key>
<string>/var/log/test-out.log</string>
当我删除此行时,错误消失了。这尤其奇怪,因为
plist
文件具有 root 权限和 launchd
以 root 身份运行...
关于macos - launchctl 无法运行二进制文件并以代码 78 退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54503366/