2

I tried the code below but it does not work:

for /f "usebackq tokens=*" %%a in (`CSCRIPT "C:/../myvbs.vbs"`) do set num=%%a

echo %num%

In the myvbs.vbs code, I am passing the number as follows:

wscript.echo number
7
  • 2
    You missed the apostrophes to enclose the command: for /f "usebackq tokens=*" %%a in ('CSCRIPT "C:/../myvbs.vbs"') do set num=%%a Commented Aug 30, 2016 at 16:42
  • I missed it. Thank you. I tried enclosing within apostrophe. It didn't work. for /f "usebackq tokens=*" %%a in ('CSCRIPT "C:\..\myvbs.vbs"') do set num=%%a Commented Aug 30, 2016 at 16:54
  • I got that. I am supposed to enclose within `` not single quote '' Commented Aug 30, 2016 at 17:03
  • In case usebackq is provided, enclose the command line within back-ticks; without usebackq, use apostrophes... Commented Aug 30, 2016 at 18:11
  • Thank you for the clarification. Commented Aug 30, 2016 at 18:24

2 Answers 2

1

Apart from the forward slashes which should be backward slashes, you've stipulated to use back quotes without using them.

for /f "usebackq tokens=*" %%a in (`CSCRIPT "C:\..\myvbs.vbs"`) do…

Although technically they shouldn't be needed

for /f "tokens=*" %%a in ('CSCRIPT "C:\..\myvbs.vbs"') do…
Sign up to request clarification or add additional context in comments.

3 Comments

@newuser, it certainly helps if your comment is entered below my correct solution/answer, and any reputation.
I used back slashes in my actual code. I posted it wrong here. Thank you for the correction.
Please check my response again… The solution, which I provided you with was using back quotes, as you had opted out of using standard single quotes, (although also missing in your post), with your usebackq entry. I fixed the backslashes only because @Aacini didn't.
0

try this:

myvbs.vbs

returnIntegerValue = 5
WScript.Quit returnIntegerValue

test.bat

cscript.exe myvbs.vbs
echo %ERRORLEVEL%

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.