[英]Portable application not showing in win32com browser, how to dispatch it?
[英]Starting matlab with win32com Dispatch, application closes itself
我正在嘗試從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")
代碼運行良好,但是在handle.Execute(command)
之前,matlab關閉了。 我是否在這里缺少一些東西,例如open()左右? 我已經看到其他人(幾乎)使用相同的代碼,並說它可以正常工作,無法解決這個問題。
編輯:Matlab版本r2012b,python版本2.7
編輯2:我大概找到了為什么關閉MATLAB。 我正在從wxPython內置的GUI中調用DispatchEx,該GUI包含一個主循環。 我嘗試使用沒有GUI的簡單腳本,並且一切正常。 如果有人遇到相同的問題或找到了解決方案,我將在此處保留此問題。
從python進行 QA 調用MATLAB函數表示應該沒有問題。 這個Matlab頁面建議您可能必須配置Matlab安裝以接受以這種方式打開。
注意:作為COM服務器對象的'matlab.application'不太可能與您發現的matlab包裝有關。 包裝器只是一個可執行文件。 matlab庫之一已注冊為matlab.application的COM服務器。
使用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
,但我保證您可以使用Dispatch
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.