3

Say you have a very simple one-liner VBScript command you need to run, something like getting the day of the month for yesterday:

wscript.echo day(date()-1)

At the moment, I have to either have a separate .vbs file and then run it with:

for /f %%a in ('cscript //nologo myscript.vbs') do set dd=%%a

or, if I don't want to maintain the script separately:

echo wscript.echo day(date()-1) >temp.vbs
for /f %%a in ('cscript //nologo temp.vbs') do set dd=%%a
del /s temp.vbs >nul: 2>nul:

Now I don't mind the hideous for statement to capture the output, I'd just like to know if there's a way to avoid having to either maintain a separate VBScript file, or create and destroy one on the fly.

Something like:

cscript //nologo //exec wscript.echo day(date()-1)

would be ideal, but I know cscript doesn't support this.

Is there any way to achieve this, keeping in mind I want to capture its output into a variable from a cmd script?

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953

1 Answers1

2

You can write one script that echoes the Eval'ed argument(s):

WScript.Echo Eval(WScript.Arguments(0))

or one script that echoes the result of a computation specified by its (first) argument:

Select Case WScript.Aruments(0)
  Case "prevday"
    wscript.echo day(date()-1)
  Case "answer"
    WScript.Echo 4711
  ...
Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96