12

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?

phuclv
  • 37,963
  • 15
  • 156
  • 475
chuck taylor
  • 2,476
  • 5
  • 29
  • 46
  • 2
    [Check `WScript.Arguments`](http://technet.microsoft.com/en-us/library/ee156618.aspx). – SLaks Jun 16 '10 at 14:56

1 Answers1

15

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"
Tisho
  • 8,320
  • 6
  • 44
  • 52
Dane Balia
  • 5,271
  • 5
  • 32
  • 57
  • C:\Windows\wscript.exe? maybe C:\Windows\System32\wscript.exe C:\xx.js "apples and bananas" – Garric Nov 18 '20 at 08:39