0

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 ?

2
  • What do you mean by hardcode the parameter values? Commented Sep 11, 2012 at 19:46
  • i want to set values for DBNAME, DBServer, DBUser, password Commented Sep 11, 2012 at 19:52

1 Answer 1

4

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thank You LittleBobbyTables... I have never worked with batch files..thanks for your help..

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.