Python 使用win32com调度启动matlab,应用程序自动关闭

Python 使用win32com调度启动matlab,应用程序自动关闭,python,matlab,wxpython,win32com,Python,Matlab,Wxpython,Win32com,我正在尝试从python启动matlab,然后执行一个非常基本的测试 def execute_matlab_command(command): handle = win32com.client.DispatchEx('matlab.application') handle.visible = True # By using print I know that the handle is valid here handle.Execute(command) exe

我正在尝试从python启动matlab,然后执行一个非常基本的测试

def execute_matlab_command(command):
    handle = win32com.client.DispatchEx('matlab.application')
    handle.visible = True
    # By using print I know that the handle is valid here
    handle.Execute(command)

execute_matlab_handle("x=32")
代码运行正常,但matlab在调用
handle.Execute(command)
之前关闭。我是不是遗漏了什么,比如一个open()之类的?我曾看到其他人使用(几乎)相同的代码,并说它工作得很好,我无法理解这个问题

编辑:Matlab版本r2012b,python版本2.7


编辑2:我可能找到了matlab关闭的原因。我从一个内置于wxPython的GUI调用DispatchEx,它包含一个主循环。我尝试了一个没有GUI的简单脚本,一切都很好。如果有人有相同的问题或找到了解决方案,我将把这个问题留在这里。

使用
Dispatch

def execute_matlab_command(command):
    handle = win32com.client.Dispatch('matlab.application')
    handle.visible = True
    # By using print I know that the handle is valid here
    handle.Execute(command)
我以前没有使用过DispatchEx,但我保证DispatchEx将正常工作。

质量保证表明不会出现问题。这意味着您可能必须配置Matlab安装以接受以这种方式打开


注意:“matlab.application”是一个COM服务器对象,不太可能与您发现的matlab包装器有关;包装器只是一个可执行文件。其中一个matlab库已注册为matlab.application的COM服务器

Matlab启动,但在满载时关闭,不运行命令。Dispatch Don autoclose?这个问题解决了吗?添加了一个答案,因为我从其他问题和方法中找到了答案。