2016-02-06 232 views
0

我跑这每一分钟来调试,并保持与com.apple.xpc.launchd[1] (com.me.DesktopChanger[16390]): Service exited with abnormal code: 2简单的launchd运行Python脚本

<?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> 
    <!-- The label should be the same as the filename without the extension --> 
    <string>com.me.DesktopChanger</string> 
    <!-- Specify how to run your program here --> 
    <key>ProgramArguments</key> 
    <array> 
     <string>/usr/bin/python</string> 
     <string>~/Library/Application\ Support/DesktopChanger/DesktopChanger.py</string> 
    </array> 

     <key>StartInterval</key> 
     <integer>60</integer> 
</dict> 
</plist> 

返回的launchd脚本称为:com.me.DesktopChanger.plist

的Python脚本位于:/Users/Tom/Library/Application Support/DesktopChanger/DesktopChanger.py

which python回报:/usr/bin/python

飞奔摹ls -l也返回:

[email protected] 1 Tom staff 623 6 Feb 13:40 com.me.DesktopChanger.plist

ls -l显示了python脚本:

[email protected] 1 Tom staff 672 2 Dec 14:24 DesktopChanger.py

回答

0

您是否尝试过不使用该脚本的相对路径?

<string>/Users/Tom/Library/Application\ Support/DesktopChanger/DesktopChanger.py</string> 

是否使用LaunchControl?我建议你使用它,所以你可以轻松捕捉标准错误控制台,看看有什么异常的底层代码2.不LaunchControl,你还可以将这些项添加到的.plist:

<key>StandardErrorPath</key> 
<string>/tmp/com.your.thing.err</string> 
<key>StandardOutPath</key> 
<string>/tmp/com.your.thing.out</string> 
+0

我尝试添加错误处理并尝试使用相对路径。当我尝试卸载Launchd脚本时发现错误消息,说'launchd无法直接运行' – Tom

+0

您是否尝试使用脚本的绝对路径?控制台中的标准错误输出是什么?你尝试安装LaunchControl并使用它进行调试吗?这对我帮助很大。 – wij

+0

我用LaunchControl试过它,它声明它运行“Ok”,但python脚本似乎没有执行 – Tom