Search code examples
asp.netcmdparametersparameter-passingwscript.shell

How to pass two arguments to cmd via wscript.shell


We use an aspx webpage that has two variables in the link. Example:

aspxpage.aspx?argument1=arg1&argument2=arg2

the aspx calls a .cmd and needs to pass the two arguments to it divided by a space. When I started working on this, no arguments were passed. The code was:

dim wshell
dim arg1
dim arg2
dim runcmd

arg1 = Request.Querystring("arg1")
arg2 = Request.Querystring("arg2")

wshell = CreateObject("WScript.Shell") 
runcmd = """path\to\run.cmd """ + arg1 + " " + arg2
wshell.run (runcmd, 1, true )
wshell = nothing

The result was nothing as no argument was passed to the .cmd and no errors occured.

Changed the runcmd line to:

runcmd = """path\to\run.cmd"" " & arg1 & " """ & arg2 & """"

The result shows that only arg1 is being passed. No error message occurs.

How to establish that also arg2 is being passed.

Have found similar questions but using that code has no result and gives errors that the closing “ are missing etc.

Passing parameters from vbscript to batch file first answer second line of code is same setup as my code, but is not working.


Solution

  • CMD was running more often than the result showed in the webpage. It ran by using following code:

    runcmd = """path\to\run.cmd"" " & arg1 & " " & arg2 & ""