Forum Moderators: open

Message Too Old, No Replies

Running Javascript from the command prompt?

have a .bat that runs a .js, but all it does is open dreamweaver

         

ziggystardust

3:29 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



I just got a .bat file that contains one line:
validate.js myxmlfile.xml 

When I run this file, it opens Dreamweaver, I'm assuming that is because DW is the app associated with .js files.

I've never heard of running .js files directly from the command prompt, but It's obviously possible (since someone wrote a .bat and sent it to me). What do I need to do to make it work?

Thanks for your help ;)
//ZS

Bernard Marx

5:14 pm on Aug 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I missed out on DOS, and clumsy with Windows scripting (which is what's being asked for here).

There are 2 applications that are relevant:
WScript.exe [C:\windows]
CScript.exe [C:\windows\command]

These run .js ¦ .wsf ¦ .vbs files.

CScript is more associated with the command line, but I'll go for WScript.exe.
Here's a quick demo:

1. create this JScript file
save it in C directory, (as xx.js)


...... xx.js .......

alert = function(s){WScript.Echo(s)}

var arg = WScript.arguments(0)
alert(arg.toUpperCase() + " now upper case")
....................

2. open the command prompt, and type (assuming at C:\> prompt)

C:\> windows\wscript.exe xx.js "apples and bananas"

then return

What we have is:

<path to script host><path to .js file><argument for .js file>

I'm assuming that in your case, the .xml file path is sent as an arg to the script file.
What's missing is the path to scripting host.

PS. Try dragging & dropping the xml file onto the .js file. See what happens.

ziggystardust

6:30 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



Muchas gracias, I'll try your suggestions first thing tomorrow (when I get to work) ;)

//ZS