Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calling vbscript from batch file doesn't work? 1

Status
Not open for further replies.

jcw009

MIS
Jul 23, 2004
3
US
i wrote run.bat which consists of:
cscript //nologo %1

i call arguments with this batch file which consists of:
Option Explicit
Dim strArgument
For Each strArgument in Wscript.Arguments
Wscript.Echo strArgument
Next

but it doesn't return anything.

if i call arguments.vbs from the command line in a normal fashion:
cscript //nologo arguments.vbs
it works.

any hints?
 
Hello jcw009,

You may have a confusion on the arguments and which script receives those arguments.

[1] The batch file (say abc.bat)
[tt] cscript //nologo %1[/tt]
[2] The argument.vbs
[tt] Option Explicit
Dim strArgument
For Each strArgument in Wscript.Arguments
Wscript.Echo strArgument
Next[/tt]

Then at commandprompt say:
>abc.bat argument.vbs
The argument.vbs being the argument for the batch file %1 will pass and run. However the argument.vbs itself receive no argument of its own, hence wscript.Arguments is empty. Consequently, nothing happens.

To show some sign of life, try this batch file (say def.bat):
[tt] @echo off
cscript %1 "Hello world!" //nologo[/tt]

In that case, run at commandprompt again
>def.bat argument.vbs
You'll see the message echoed.

regards - tsuji
 
You did not provide an example of how you are calling the batch file. If you are doing this:

run arguments.vbs Hello World

..then you will be passing 3 arguments to the batch file. But you have only handled one argument in the batch file and the others are discarded.

If you make run.bat to be:

cscript %1 //nologo %2 %3 %4 %5 %6 %7 %8 %9

..then argument 1 for the batch file will be the script to run and arguments 2 through 9 for the batch file will become arguments 1 through 8 for the script.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top