Skip to main content
Post Undeleted by Vomit IT - Chunky Mess Style
Post Deleted by Vomit IT - Chunky Mess Style
added 324 characters in body
Source Link

Passing in classic batch script cmd arguments when executing the second.bat should do this no problem. Using this method eliminates the need altogether to even have to change any content of second.bat.

It essentially makes second.bat dynamic and uses the passed in argument paramater(s) as variables which contain the placeholder values for the passed in arument values (e.g. %~1,%~2, etc.) for the passed in argument values (e.g "flockingbird" "clockingmerge" "wishyword").

Second.bat

SET "dbuser=%~1"
FOR /F "tokens=*" %%g IN ('echo %dbuser%') do (SET "myuser=%%~g")
etc

Executing

Executing

You can choose whatever method works best for executing or calling the second.bat script whether using call, start, something like second.bat "flockingbird" or any other ways that works to pass in the argument value at execution time of second.bat


Another Example

Batch

@echo off
set "dbname=%~1"
set "dbuser=%~2"
set "dbpass=%~3"

echo %dbname%
echo %dbuser%
echo %dbpass%

pause

To Execute

C:\Folder\second.bat "flockingbird" "clockingmerge" "wishyword"

Output

flockingbird
clockingmerge
wishyword

Supporting Resources

  • Command line parameters

    Batch files can only handle parameters %0 to %9

    %0 is the program name as it was called, %1 is the first command line parameter, %2 is the second command line parameter, and so on till %9.

  • Pass Command Line arguments (Parameters) to a Windows batch file

    %~1 Expand %1 removing any surrounding quotes (")

  • Start

  • Call

    CALL a second batch file

    The CALL command will launch a new batch file context along with any specified parameters. When the end of the second batch file is reached (or if EXIT is used), control will return to just after the initial CALL statement.

    Arguments can be passed either as a simple string or using a variable:

    CALL MyScript.cmd "1234" CALL OtherScript.cmd %_MyVariable%

Passing in classic batch script cmd arguments when executing the second.bat should do this no problem. Using this method eliminates the need altogether to even have to change any content of second.bat.

It essentially makes second.bat dynamic and uses the passed in argument paramater(s) as variables which contain the placeholder values for the passed in arument values (e.g. %~1,%~2, etc.)

Second.bat

SET "dbuser=%~1"
FOR /F "tokens=*" %%g IN ('echo %dbuser%') do (SET "myuser=%%~g")
etc

Executing

You can choose whatever method works best for executing or calling the second.bat script whether using call, start, something like second.bat "flockingbird" or any other ways that works to pass in the argument value at execution time of second.bat

Supporting Resources

  • Command line parameters

    Batch files can only handle parameters %0 to %9

    %0 is the program name as it was called, %1 is the first command line parameter, %2 is the second command line parameter, and so on till %9.

  • Pass Command Line arguments (Parameters) to a Windows batch file

    %~1 Expand %1 removing any surrounding quotes (")

  • Start

  • Call

    CALL a second batch file

    The CALL command will launch a new batch file context along with any specified parameters. When the end of the second batch file is reached (or if EXIT is used), control will return to just after the initial CALL statement.

    Arguments can be passed either as a simple string or using a variable:

    CALL MyScript.cmd "1234" CALL OtherScript.cmd %_MyVariable%

Passing in classic batch script cmd arguments when executing the second.bat should do this no problem. Using this method eliminates the need altogether to even have to change any content of second.bat.

It essentially makes second.bat dynamic and uses the passed in argument paramater(s) as variables which contain the placeholder values (e.g. %~1,%~2, etc.) for the passed in argument values (e.g "flockingbird" "clockingmerge" "wishyword").

Second.bat

SET "dbuser=%~1"
FOR /F "tokens=*" %%g IN ('echo %dbuser%') do (SET "myuser=%%~g")
etc

Executing

You can choose whatever method works best for executing or calling the second.bat script whether using call, start, something like second.bat "flockingbird" or any other ways that works to pass in the argument value at execution time of second.bat


Another Example

Batch

@echo off
set "dbname=%~1"
set "dbuser=%~2"
set "dbpass=%~3"

echo %dbname%
echo %dbuser%
echo %dbpass%

pause

To Execute

C:\Folder\second.bat "flockingbird" "clockingmerge" "wishyword"

Output

flockingbird
clockingmerge
wishyword

Supporting Resources

  • Command line parameters

    Batch files can only handle parameters %0 to %9

    %0 is the program name as it was called, %1 is the first command line parameter, %2 is the second command line parameter, and so on till %9.

  • Pass Command Line arguments (Parameters) to a Windows batch file

    %~1 Expand %1 removing any surrounding quotes (")

  • Start

  • Call

    CALL a second batch file

    The CALL command will launch a new batch file context along with any specified parameters. When the end of the second batch file is reached (or if EXIT is used), control will return to just after the initial CALL statement.

    Arguments can be passed either as a simple string or using a variable:

    CALL MyScript.cmd "1234" CALL OtherScript.cmd %_MyVariable%

Source Link

Passing in classic batch script cmd arguments when executing the second.bat should do this no problem. Using this method eliminates the need altogether to even have to change any content of second.bat.

It essentially makes second.bat dynamic and uses the passed in argument paramater(s) as variables which contain the placeholder values for the passed in arument values (e.g. %~1,%~2, etc.)

Second.bat

SET "dbuser=%~1"
FOR /F "tokens=*" %%g IN ('echo %dbuser%') do (SET "myuser=%%~g")
etc

Executing

You can choose whatever method works best for executing or calling the second.bat script whether using call, start, something like second.bat "flockingbird" or any other ways that works to pass in the argument value at execution time of second.bat

Supporting Resources

  • Command line parameters

    Batch files can only handle parameters %0 to %9

    %0 is the program name as it was called, %1 is the first command line parameter, %2 is the second command line parameter, and so on till %9.

  • Pass Command Line arguments (Parameters) to a Windows batch file

    %~1 Expand %1 removing any surrounding quotes (")

  • Start

  • Call

    CALL a second batch file

    The CALL command will launch a new batch file context along with any specified parameters. When the end of the second batch file is reached (or if EXIT is used), control will return to just after the initial CALL statement.

    Arguments can be passed either as a simple string or using a variable:

    CALL MyScript.cmd "1234" CALL OtherScript.cmd %_MyVariable%