bash里面有python3里面的applescript返回值

时间:2016-09-30 01:02:40

标签: bash macos apache python-3.x

我正在为OSX / macOS中的内置apache服务器的控制面板工作 我正在尝试检查服务器的状态 - 它是否正在运行。在mac中,没有实际的单一命令来检查服务器是否通过httpd / apachectl运行(我正在使用后者)。所以我试图通过启动服务器来检查,然后它是否给出一个返回值为'所有好的' (或在os.system()的情况下,0)然后再将其关闭并说它没有运行,或者如果它返回错误,说它已经在运行。基本上我需要获取我在AppleScript中执行的bash的返回值,并且返回值进入我的python脚本的其余部分。这就是我到目前为止所做的:

status = os.system('''
    osascript -e 'do shell script "sudo apachectl start" with administrator privileges'
''')

if (status == 0):
    os.system('''
        osascript -e 'do shell script "sudo apachectl stop" with administrator privileges'
    ''')
    statusText.config(state=NORMAL)
    statusText.insert(END, "Not Running")
    statusText.config(state=DISABLED, fg="red")
else:
    statusText.config(state=NORMAL)
    statusText.insert(END, "Running")
    statusText.config(state=DISABLED, fg="green")

我打算将它作为一个独立的应用程序,所以我需要所有内置函数。 提前谢谢!

0 个答案:

没有答案