我正在尝试让 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运行没有问题
我按照中的说明进行操作这个问题已经,但没有运气
不久前我使用 cron 来做到这一点。你可以这样输入
@reboot /path/to/my/script
有关 cron 的更多信息
我的脚本的路径将是您的 appstart.sh 文件的路径。
所以你打开你的终端。
您输入crontab -e
(这将在您的默认编辑器中打开一个文件,可能是 nano)
您向下滚动并在您键入的文件的底部@reboot /path/to/file
然后保存并退出。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)