我想用launchd每分钟运行一个python脚本.我的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.turtle.script.plist</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/python</string>
<string>/Users/turtle/Desktop/turtle.py</string>
<string>/Users/turtle/Desktop/data/data.txt</string>
</array>
<key>StartInterval</key>
<integer>60</integer>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)
这个plist文件看起来很好,因为我得到以下内容:
plutil -lint com.turtle.script.plist
com.turtle.script.plist: OK
Run Code Online (Sandbox Code Playgroud)
当我从命令行运行脚本时,脚本可以正常工作:
/usr/bin/python /Users/turtle/Desktop/turtle.py /Users/turtle/Desktop/data/data.txt
Run Code Online (Sandbox Code Playgroud)
我通过以下方式加载此plist:
launchctl load -w -F com.turtle.script.plist
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
sudo launchctl load -w -F com.turtle.script.plist
Run Code Online (Sandbox Code Playgroud)
我加载这个作业,python脚本应该写出一个文件到磁盘.但是没有生成任何文件.我检查了这份工作:
sudo launchctl list | grep com.turtle.script.plist
Run Code Online (Sandbox Code Playgroud)
输出是:
- 1 com.turtle.script.plist
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助解决问题吗?