Call .vbs File from Javascript Opaque Action

Moderator: Moderators

Call .vbs File from Javascript Opaque Action

Postby phathom.a.donald@lmco.com » Wed Mar 22, 2017 12:35 pm

Is it possible to call a .vbs file from a opaque action written in Javascript, or in any of the languages available to opaque actions/behaviors?
phathom.a.donald@lmco.com
Forum Beginner
Forum Beginner
 
Posts: 62
Posts Rating:1
Joined: Fri May 13, 2016 7:09 am

Re: Call .vbs File from Javascript Opaque Action

Postby chanon_s » Fri Mar 24, 2017 12:58 am

Dear Phathom

Please try to set the language of the opaque action to BeanShell and use the following script expressions:

Code: Select all
String[] cmd = {"cscript", "fullpath_to_your_vbs_file"};
Runtime.getRuntime().exec(cmd);


Where fullpath_to_your_vbs_file is the full path to your vbs file, for example, D:/test.vbs

Sincerely

Chanon S.
No Magic Customer Support
chanon_s
Customer Support
Customer Support
 
Posts: 91
Posts Rating:7
Joined: Thu Dec 04, 2014 2:21 am

Re: Call .vbs File from Javascript Opaque Action

Postby phathom.a.donald@lmco.com » Mon Mar 27, 2017 6:24 am

Thank you for your response. I entered the code you suggested and got the following error message:

2017-03-27 06:25:26,252 ERROR: Cannot evaluate Opaque Action IncrementTime: bsh.EvalError: Sourced file: inline evaluation of: ``String[] cmd = {"cscript", "C:\Users\e304\Documents\Rex\IncrementTime. . . . '' Token Parsing Error: Lexical error at line 1, column 32. Encountered: "U" (85), after : "\"C:\\": <at unknown location> in <unknown file> expression body: String[] cmd = {"cscript", "C:\Users\e304\Documents\Rex\IncrementTime.vbs"}; Runtime.getRuntime().exec(cmd);
phathom.a.donald@lmco.com
Forum Beginner
Forum Beginner
 
Posts: 62
Posts Rating:1
Joined: Fri May 13, 2016 7:09 am

Re: Call .vbs File from Javascript Opaque Action

Postby chanon_s » Mon Mar 27, 2017 9:54 pm

Dear Phathom

Please check the path file separator. If you are going to use a slash (/), as demonstrated in our script example, it is okay to use a single one. However, if you are going to use a backslash (\), you need to use the double-backslash in your file path, as displayed below:

Code: Select all
String[] cmd = {"cscript", "C:\\Users\\e304\\Documents\\Rex\\IncrementTime.vbs"};
Runtime.getRuntime().exec(cmd);


Sincerely

Chanon S.
No Magic Customer Support
chanon_s
Customer Support
Customer Support
 
Posts: 91
Posts Rating:7
Joined: Thu Dec 04, 2014 2:21 am

Re: Call .vbs File from Javascript Opaque Action

Postby phathom.a.donald@lmco.com » Tue Mar 28, 2017 7:41 am

That removed the error, thank you!

Now the activity diagram execution terminates abruptly after the opaque action is finished executing. Is it possible to link values on the input/output pins of the opaque action to variables in the .vbs file? I have variables declared in the .vbs file with the same names as the pins and my output variable has the same name as my file and function. See below for the code I used.

Code: Select all
String[] cmd = {"cscript", "C:\\Users\\e304\\Documents\\Rex\\NewCurrentTime.vbs", CurrentTime, String.valueOf(TimeStep)};
Runtime.getRuntime().exec(cmd);
phathom.a.donald@lmco.com
Forum Beginner
Forum Beginner
 
Posts: 62
Posts Rating:1
Joined: Fri May 13, 2016 7:09 am

Re: Call .vbs File from Javascript Opaque Action

Postby chanon_s » Wed Mar 29, 2017 3:15 am

Dear Phathom

Could you please attach the sample project you are using, including the IncrementTime.vbs file?

Please be informed that we are not Vbscript experts. From what we have done researching, we have not found any script engine that is directly able to support running vbscripts. The solution previously given was indirect, which was found on the Internet. So, it would not be able to directly access/return any values from/to the input/output pins, respectively.

We found a solution to pass arguments when running a vbscript via the cscript command. You can access arguments with the following syntax:

Code: Select all
WScript.Arguments(0)
'WScript.Arguments(index), where index is zero based.
'Also you can check the number of the arguments passed in your script by using WScript.Arguments.Count


However, we have not yet found any solution to return the value from the vbscript calling.

Sincerely

Chanon S.
No Magic Customer Support
chanon_s
Customer Support
Customer Support
 
Posts: 91
Posts Rating:7
Joined: Thu Dec 04, 2014 2:21 am


Return to Cameo Simulation Toolkits

Who is online

Users browsing this forum: No registered users and 1 guest

cron