Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
加载OSX plist以使用python子进程启动守护进程_Python_Plist_Subprocess_Launchd - Fatal编程技术网

加载OSX plist以使用python子进程启动守护进程

加载OSX plist以使用python子进程启动守护进程,python,plist,subprocess,launchd,Python,Plist,Subprocess,Launchd,我试图使用python安装OSX LaunchDaemon,但使用subprocess.Popen调用launchctl实际上并没有安装该服务 我在/Library/LaunchDaemons/中有plist文件,我可以使用终端加载plist文件: $启动ctl加载-w/Library/LaunchDaemons/com.myplist.file.plist $launchctl startcom.myplist.file $启动CTL列表 “-0 com.myplist.file” 服务通过命

我试图使用python安装OSX LaunchDaemon,但使用subprocess.Popen调用launchctl实际上并没有安装该服务

我在/Library/LaunchDaemons/中有plist文件,我可以使用终端加载plist文件:

$启动ctl加载-w/Library/LaunchDaemons/com.myplist.file.plist

$launchctl startcom.myplist.file

$启动CTL列表

“-0 com.myplist.file”

服务通过命令行正确加载和启动,这意味着我的plist文件设置正确,但当我使用python subprocess.Popen或任何python系统调用命令执行相同的命令时,问题就开始了

            # Load the service
            command = shlex.split("launchctl load -w /Library/LaunchDaemons/com.myplist.file.plist")
            subprocess.Popen(command)
            # Start the service
            command = shlex.split("launchctl start com.myplist.file")
            subprocess.Popen(command)

我也试过设置shell=True,但运气不好。对此有什么想法吗?

我已经想明白了!谢谢你的帮助,赛尔夫。哦,不客气,赛尔夫

任何想通过python安装OSX服务的人都会发现这很有用

加载服务 启动服务
servicePath = '/Library/LaunchDaemons/com.myplist.file.plist'

launchctlCmd = ['/bin/launchctl', 'load', '-w', servicePath]
# Execute service load command
proc = subprocess.Popen(launchctlCmd, shell=False, bufsize=1, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
serviceName = 'com.myplist.file'

launchctlCmd = ['/bin/launchctl', 'start', serviceName]
# Execute service start command
proc = subprocess.Popen(launchctlCmd, shell=False, bufsize=-1, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)