Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing arguments to javascript through cscript on the command line

Tags:

wsh

jscript

I have a small command line JScript routine that I usually run from the command line using cscript in windows. I'd like to be able to pass in arguments hopefully along the lines of...

%:>cscript doSomethingToFile.js FileInQuestion.txt

Any insight on how to do this? Thanks much.

like image 533
chuck taylor Avatar asked Jun 16 '10 14:06

chuck taylor


1 Answers

From Bernard Marx

  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")
...
  1. Open the command prompt, and type

(assuming at C:> prompt):

C:\> windows\wscript.exe xx.js "apples and bananas"
like image 125
Dane Balia Avatar answered Sep 20 '22 21:09

Dane Balia