3

我正在尝试从 python-daemon 调用脚本,但它不起作用。这就是我要做的,对吗?

我还想向该脚本传递一个随机参数,目前我已经对其进行了硬编码

import daemon
import time
import subprocess
import os

def interval_monitoring():
    print "Inside interval monitoring"
    while True:
        print "its working"
#         os.system("XYZ.py 5416ce0eac3d94693cf7dbd8") Tried this too but not working
        subprocess.Popen("XYZ.py 5416ce0eac3d94693cf7dbd8", shell=False)
        time.sleep(60)
        print "condition true"




def run():
    print daemon.__file__
    with daemon.DaemonContext():
        interval_monitoring()

if __name__ == "__main__":
    run()
4

1 回答 1

0

If you didn't make XYZ.py executable and added #!/usr/bin/env python in the top line, you need to call it via python, rather than directly. So your line would be something like this:

subprocess.check_output(["python", "XYZ.py", "5416ce0eac3d94693cf7dbd8"])

于 2014-10-26T12:04:28.183 回答