msbyuva
msbyuva

Reputation: 3615

how to pass parameter values to batchfiles

I have a bacthfile & I want to pass parameter values, how can I do it ?

@echo off
ECHO Param1: Database Name: %1
ECHO Param2: Datasource : %2
ECHO Param3: DB User Id: %3
ECHO Param4: Password: %4

SET DBNAME=%1
SET DBSERVER=%2
SET DBUSER=%3
SET PASSWORD=%4

values which I want to set are DBNAME, DBSERVER, DBUSER and PASSWORDare parameters for batch file ?

Upvotes: 0

Views: 1301

Answers (1)

You just pass parameters to a batch file by appending them to the end of the file name, with a space between each parameter:

FOO.BAT NorthwindDB ServerName msbyuva 12345

And if you need to pass spaces in a parameter, just surround it in quotes:

FOO.BAT NorthwindDB "Server Name" msbyuva 12345

And if you need to remove those quotes in FOO.BAT you can use ~ notation:

set ServerName=%~2

Upvotes: 4

Related Questions