简体   繁体   中英

How to run vbs file and pass argument/parameter to bat file?

This VBS will help me to hide the CMD prompt when calling a batch file. Both files are in the same location.

Here is my VBS code:

CreateObject("Wscript.Shell").Run "b.bat" & Wscript.Arguments.Item(0),0, False

Here is the batch file code:

if [%1]==[] GOTO :EXIT
Echo abc > %1
:EXIT

and I start my command prompt like this:

c:...\Desktop>a.vbs "a.txt"

The error I get says this:

Error: The system cannot find the file specified.

The batch file will create an empty txt file whose name is specified as a parameter.

Appreciate you help. Thanks.

Be careful with spaces in your command. This:

CreateObject("Wscript.Shell").Run "b.bat" & Wscript.Arguments.Item(0),0, False

Should be:

CreateObject("Wscript.Shell").Run "b.bat " & Wscript.Arguments.Item(0),0, False

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM