Bash Python在使用启动代理重新启动后未运行Shell命令

Bash Python在使用启动代理重新启动后未运行Shell命令,bash,python-2.7,subprocess,launchd,Bash,Python 2.7,Subprocess,Launchd,因此,我正在macOS 10.13上通过启动代理启动Python(2.7)脚本。脚本将运行,并在执行期间触发计算机重新启动。当计算机重新打开并登录时,启动代理将再次运行脚本。该脚本读取日志,并执行switch:case来选择它停止的位置 问题是,重新启动后,python脚本无法执行某些shell命令ls-l工作正常。然而,当我试图运行一些不在/bin中的东西时,它似乎只是。。。跳过它。没有错误,它根本就做不到 这是相关代码。我已经删除了大部分细节,以及开关控制,因为我已经验证了它们是独立工作的

因此,我正在macOS 10.13上通过启动代理启动Python(2.7)脚本。脚本将运行,并在执行期间触发计算机重新启动。当计算机重新打开并登录时,启动代理将再次运行脚本。该脚本读取日志,并执行switch:case来选择它停止的位置

问题是,重新启动后,python脚本无法执行某些shell命令
ls-l
工作正常。然而,当我试图运行一些不在/bin中的东西时,它似乎只是。。。跳过它。没有错误,它根本就做不到

这是相关代码。我已经删除了大部分细节,以及开关控制,因为我已经验证了它们是独立工作的

#!/usr/bin/python

import logging
import os
import subprocess
import time

#globals
path_to_plist = 'User/Me/Library/Preferences/PathTo.plist'


def spot_check():
    #determine where we are in the test, verified it works
    return loop_number

def func_that_checks_stuff():
    results = subprocess.check_output(['System/Library/Path/To/tool','-toolarg'])
    ###process results
    logging.info(results)

def restarts(power_on, power off):
    #sets plist key values for the restart app
    subprocess.Popen('defaults write {} plist_key1 {}'.format(path_to_plist, power_on), shell=True
    subprocess.Popen('defaults write {} plist_key2 {}'.format(path_to_plist, power_off), shell=True

    #run the restart app, which is a GUI application in /Applications
    logging.info('Starting restart app')
    subprocess.Popen('open -a RestartApp.app', shell=True)
    time.sleep(power_on + 5)

def main():
    ###setup and config stuff, verified its working

    #switch control stuff, verified its working
    loop = spot_check()

    if loop == 0:
        #tool that shows text on the screen
        subprocess.Popen('User/Me/Library/Scripts/Path/To/Text/tool -a -args', shell=True)
        logging.info('I just ran that tool')
        subprocess.check_output('ls -l', shell=True)
        restarts(10, 0)
    if loop == 1:
        func_that_checks_stuff()
        subprocess.Popen('User/Me/Library/Scripts/Path/To/Text/tool -a args', shell=True)
        logging.info('Hey I ran that tool again, see?')
        restarts(10, 0)
    else:
        func_that_checks_stuff()
        subprocess.Popen('User/Me/Library/Scripts/Path/To/Text/tool -a args', shell=True)

    print 'You finished!'

if __name__ == '__main__':
    main()
所以,如果我用我的启动代理启动它,它将在每个序列中正常运行

  • 在第一个循环中(重新启动之前),一切正常。所有的日志记录,所有的工具,一切
  • 重启后,所有日志记录都正常工作,因此我知道它遵循开关控制。检查stuff()的
    函数起作用,并正确记录其输出。
    ls-l'调用准确地显示了我应该看到的内容。但是,
    Path/To/Text/tool
    没有运行,当我调用
    restarts()时,它永远不会打开应用程序
  • 没有产生错误,至少我能找到
我做错了什么?这与刀具路径有关吗

更新:

事实证明,解决方案是在脚本开始时增加约20秒的延迟。它似乎是在Windows Server完成加载之前尝试运行有问题的命令,这让一切都很紧张。这不是一个特别优雅的解决方案,但它可以满足我在这个项目中的需要。

更新:

事实证明,解决方案是在脚本开始时增加约20秒的延迟。它似乎是在Windows Server完成加载之前尝试运行有问题的命令,这让一切都很紧张。不是一个特别优雅的解决方案,但它可以满足我在这个项目中的需要