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?