Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tcl and javascript

Status
Not open for further replies.

rommeq

Programmer
Sep 26, 2011
6
0
0
UA
How can I execute javascript code with tcl? Operating system windows. Where can I find detailed instructions?
Found engine spidermonkey-1.8.5, but it did not work with it from tcl.

Sorry for my English.
 
Here a little example, how to call Jscript from Tcl using tcom and Windows Script Host:

I have this Tcl script:
wsh.tcl
Code:
[COLOR=#804040][b]package[/b][/color] require tcom

[COLOR=#804040][b]puts[/b][/color] [COLOR=#ff00ff]"Begin of Tcl"[/color]
[COLOR=#804040][b]set[/b][/color] wsh [::tcom::ref createobject [COLOR=#ff00ff]"WScript.Shell"[/color]]
[COLOR=#804040][b]puts[/b][/color] [COLOR=#ff00ff]"Now calling JScript example:"[/color]
[COLOR=#008080]$wsh[/color] Run example.js [COLOR=#ff00ff]3[/color] [COLOR=#ff00ff]1[/color]
[COLOR=#0000ff]# calling JScript without waiting:[/color]
[COLOR=#0000ff]# $wsh Run example.js[/color]
[COLOR=#804040][b]puts[/b][/color] [COLOR=#ff00ff]"End of Tcl."[/color]
which calls this Jscript
example.js
Code:
[COLOR=#008080]function[/color] addTwo(x, y) [COLOR=#008080]{[/color]
  [COLOR=#804040][b]try[/b][/color] [COLOR=#008080]{[/color]
    [COLOR=#804040][b]return[/b][/color](x + y);
  [COLOR=#008080]}[/color]
  [COLOR=#804040][b]catch[/b][/color]( e ) [COLOR=#008080]{[/color]
    [COLOR=#804040][b]return[/b][/color]( [COLOR=#ff00ff]"Error: "[/color] + e.description );
  [COLOR=#008080]}[/color]
[COLOR=#008080]}[/color];

[COLOR=#0000ff]// main[/color]
text = [COLOR=#ff00ff]"result of addTwo(3, 5) = "[/color] + addTwo(3, 5)
WScript.Echo(text);
WScript.Quit();

Now, when calling the Tcl script from console I get first this output from Tcl:
Code:
C:\_mikrom\Work>tclsh wsh.tcl
Begin of Tcl
Now calling JScript example:
then Tcl calls the Jscript which prints the MessageBox with:
Code:
result of addTwo(3, 5) = 8
and after clicking at MessageBox' OK button the Tcl script ends with
Code:
End of Tcl.
If you don't want, that Tcl script waits until Jscript ends use
instead of
Code:
$wsh Run example.js 3 1
only
Code:
$wsh Run example.js
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top