How do you pass a vb script variable to a batch file?

P

Pegasus \(MVP\)

Mike said:
Does anyone know how to do this?

Thanks,

Write them to standard output, then get the batch file to pick them up like
so:

@echo off
for /F %%* in ('your script command goes here') do set vars=%%*
echo Variables=%vars%

Don't forget the single quotes inside the brackets!
 
G

Guest

I don't understand. This is what I came up with:

for /F %%* in ('cscript.exe "C:\Documents and Settings\mroush\Desktop\New
Folder\GetName.vbs"') do set vars=%%*
echo Variables=%vars%
pause
"C:\Program Files\Network Associates\PGPNT\PGP.exe" -o "C:\Documents and
Settings\mroush\Desktop\New Folder\toefl.txt" "C:\Documents and
Settings\mroush\Desktop\New Folder\%vars%"
 
P

Pegasus \(MVP\)

That's about it. What is the question?


Mike said:
I don't understand. This is what I came up with:

for /F %%* in ('cscript.exe "C:\Documents and Settings\mroush\Desktop\New
Folder\GetName.vbs"') do set vars=%%*
echo Variables=%vars%
pause
"C:\Program Files\Network Associates\PGPNT\PGP.exe" -o "C:\Documents and
Settings\mroush\Desktop\New Folder\toefl.txt" "C:\Documents and
Settings\mroush\Desktop\New Folder\%vars%"
 
G

Guest

I keep getting the following output when I run this.

variables=Input

but what I need it to be is the filename stored in a variable in the vbs
file that I am executing?
 
P

Pegasus \(MVP\)

"Input" must be the last string written to standard output.
Try this for testing purposes:

cscript.exe "C:\Documents and Settings\mroush\Desktop\New
Folder\GetName.vbs" > c:\test.txt

Now examine c:\test.txt. What does it contain? Where
is the variable you wish to pass back to the batch file?
 
G

Guest

I get the filename in the test.txt file which is what I want to pass back to
the batch file. The variable I want to pass back is located in the
CheckNames.vbs file.
 
G

Guest

I got it stupid me, I left the double quotes out around the path to the vbs
file. I really appreciate your help on this Pegasus!
 
Joined
Nov 21, 2014
Messages
1
Reaction score
0
Hi there,

I would like to ask how will I pass a parameter in vbscript using that for loop?

for /F %%* in ('cscript.exe "C:\dir_list.vbs"') do set vars=%%*
echo variables=%vars%

this works, but I have to pass some argument in the dir_list.vbs..

When I try to do something like this:
(I based on this example: [cscript test.vbs /a:"a value" "another value"])

for /F %%* in ('cscript.exe "C:\dir_list.vbs /a:"value1""') do set vars=%%*
echo variables=%vars%

it didn't work. Even tried to remove the double quotes in the value1.
It only output/echo "variables=Input" instead of "variables=value1"
Any idea how will I do it?
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top