4

I would like to know how to display variable values in command prompt. Following is the vbs code:

 For i=0 To 10
 // I should display this variable value in command prompt
 Next

If I write Shell.run(a.bat) inside loop, this will open command prompt 10 times.
But i want all 10 values to be displayed in single command prompt.

1
  • 2
    How do you (want to) start your script? What is the purpose/content of a.bat? Have you considered using WScript.Echo? (BTW: Your loop loops 11 times, comments are marked with ' (not //) in VBScript, the parameter to .Run needs to be quoted, and you must not use param list () in a Sub call) Commented Jan 23, 2013 at 7:01

2 Answers 2

11

Use WScript.Echo:

For i = 0 To 10
  WScript.Echo i
Next

You'll want to use CSCRIPT, either explicitly:

cscript vecho.vbs

Or make CSCRIPT the default:

cscript //H:CScript
Sign up to request clarification or add additional context in comments.

1 Comment

Nothing. I just converted host from wscript to cscript and used WScript.Echo command. I called VBS file from Bat file so that everything got displayed in Command prompt :) Thank you
0

[EDIT] Yes, if run the .vbs script via CSCRIPT then WScript.Echo will print to the prompt window, else will popup a message box. Then work with CSCRIPT you can use as well WScript.StdOut.Write and WScript.StdOut.WriteLine

For i = 0 To 10
    WScript.StdOut.WriteLine i
Next

Also with Shell.Run you can get only the exit code, and to redirect the output from your .bat file, you'll need Shell.Exec method. There is a nice example on how to use Exec into Windows Script 5.6 Documentation. It's a must have doc file anyway.

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.