【发布时间】:2014-03-12 16:58:25
【问题描述】:
我正在尝试让 python 脚本在启动时运行。我有以下文件: com.test.service.plist :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//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.service</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>/var/www/html/app/appstart.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
复制到 ~/Library/LaunchAgents/
加载为
launchctl load -w ~/Library/LaunchAgents/com.test.service.plist
脚本有 2 行:
/usr/bin/python /var/www/html/app/app.py
echo "hello" >> /var/www/html/app/test.txt
脚本运行(文件 test.txt 被创建,其中包含 'hello') 但是,app.py 没有运行。出于测试目的,我在 app.py 中所做的只是:
import os
os.system("echo 'python' >> /var/www/html/app/test.txt")
如果我只是在终端运行 appstart.sh,那么 python 运行没有问题
我已经按照this question 中的说明进行操作,但没有运气
【问题讨论】:
-
为什么你的
app.py脚本和 bash 脚本做同样的事情? -
因为我不想在这里粘贴 200 行代码,这是测试脚本是否运行的一种非常快速简单的方法。