简体   繁体   中英

How to call Vbscript from Matlab

Is there a way to call a vbscript code in Matlab? Basically, I want to run some vbscript code and pass an output variable to Matlab.

Not directly. It should be possible via COM / ActiveX, though I suppose that would be very hacky. See http://undocumentedmatlab.com/blog/running-vb-code-in-matlab

Much easier solution:

In your VBS code, have the line:

Wscript.Echo MyOutputVariables

Where "MyOutputVariables" is your desired output

Then call from matlab with dos:

[status,message] = dos('cscript //NoLogo myvbsfile.vbs');

Where myvbsfile.vbs is the name of your script. The variable message will contain the output you're looking for.

voila!

cscript is an alternative to wscript (Windows default for VBS files) which will output the command to a console (vice a message box) - in this case, the MATLAB console since it was called from MATLAB.

The //NoLogo option removes a Microsoft message that would otherwise appear in the output. You have to use this to make the output "clean" so that you don't need to remove the messages in MATLAB itself.

I tried this in 2015a, but I'm sure it works in any version with the dos command and Windows version that supports cscript.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM