Object CreateObje​ct("MATLAB​.applicati​on") used in VBS script have different behaviours on 2 PCs

8 次查看(过去 30 天)
Hi,
I have a working VBS script that does not give me the same results on 2 different PCs which seems to have the same MATLAB configuration. Here are the order of operations:
I open a Simulink model manually, which launches a desktop MATLAB 2015b (8.6) instance. Then I start my VBS script from Windows explorer. This script first lines are :
Set ml = CreateObject("MATLAB.application")
ml.Execute("test123=1;"))
On PC #1, since I already have an instance of MATLAB running, my object ml is directly connected to this instance and I can see the variable "test123" in my workspace. If no MATLAB.exe process is running and I start the VBS script, I have a new command window instance that opens. That is what I expect.
On PC #2, I just can't connect to my existing MATLAB desktop instance. Instead, a new command window instance is created each time.
Here are the relevant differences between the two PCs :
  • PC #1 only has MATLAB 2015b installed and PC #2 has MATLAB 2011, 2014b and 2015b installed. I thought this was the problem so I changed the first line of my script to Set ml = CreateObject("MATLAB.application.8.6") to eliminate that possible problem. No success with that.
  • PC #1 is a fresh PC with not a lot of things installed on it and PC #2 has a lot of stuff installed.
Is there something I need to add in my script to differentiate "link to an existing MATLAB instance" from "create a new MATLAB instance" ?
Thanks a lot.

回答(1 个)

Alexandre
Alexandre 2022-3-2
I finally found a solution but I unfortunately can't explain it. I discovered that the PC where I run my script is not important. How my MATLAB instance was launched is important.
I open my model from a third party software (RT-LAB from Opal-RT Technologies) and this software makes the MATLAB instance controllable from a script that is executed later. That is my solution.
I tried to retro-engineer how it is done but I couldn't. The only information I have is the command line from task manager:
I thought the important thing was "-desktop -MLAutomation -desktop -r" but it seems that the software does other things in the background with a temporary file. I found the temporary file and it was empty or maybe it's just encrypted. If I execute the exact same command line outside of the software environment, I get a regular MATLAB instance that I can't control with my script.
That only proves that executing script from command line to existing MATLAB instance is not impossible but pretty complex.
If anybody was ever able to launch a controllable MATLAB instance, please share it here.
Thank you!

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

产品


版本

R2015b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by