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?

1
  • You'll be lucky! This is Windows! I too wait with baited breath :-) Commented Aug 7, 2015 at 8:24

1 Answer 1

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
  ...
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.