passing arguments to javascript through cscript on the command line
Asked Answered
C

1

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?

Cornucopia answered 16/6, 2010 at 14:50 Comment(1)
Check WScript.Arguments.Darrickdarrill
A
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"
Aeroneurosis answered 13/7, 2012 at 5:24 Comment(1)
C:\Windows\wscript.exe? maybe C:\Windows\System32\wscript.exe C:\xx.js "apples and bananas"Dickman

© 2022 - 2024 — McMap. All rights reserved.