0

I am trying to create a batch script which will take two input parameters from the user and pass those parameters to call one script which in turn should call another script. I am new to batch scripting. I have written the below code for that but the final script fails. It does not get the parameter correctly that was sent by the user.

The flow is as follow: userInput.bat calls mybat.bat, which calls startTask.bat.

Code for userInput.bat:

set /p userName="Enter the userName: "
echo %userName%
set /p dateofbirth="Enter the dateofbirth: "
echo %dateofbirth%
CALL mybat.bat %userName% %dateofbirth% 

Code for mybat.bat:

CALL startTask.bat %1 "myHouseAddress" %2
CALL startTask.bat %1 "myOfficeAddress" %2

Code for startTask.bat:

java -classpath joda-time-1.6.jar com.mycode.somecode.KickOffTask %1 %2 %3
1
  • 1
    So, did you find out in what file is the problem? Did you debug/echo the variables? Commented Dec 29, 2016 at 10:35

1 Answer 1

1

Your script seems to work fine, unless that script is only part of your program

I've made some improvements:

  • Changed %username% to %user%, as the %username% is a predefined variable
  • Added error checking
  • Added support for spaces in variables

userinput.bat:

@echo off
:query.user
    set "user="
    set /p user="Enter the username: "
    if not defined user (goto query.user) else (echo user=%user%)

:query.dateofbirth
    set "dateofbirth="
    set /p dateofbirth="Enter dateofbirth: "
    if not defined dateofbirth (goto query.dateofbirth) else (echo dateofbirth=%dateofbirth%)

call mybat.bat "%user%" "%dateofbirth%"

mybat.bat:

@echo off
call startTask.bat "%~1" "myHouseAddress" "%~2"
call startTask.bat "%~1" "myOfficeAddress" "%~2"

startTask.bat:

@echo off
java -classpath joda-time-1.6.jar com.mycode.somecode.KickOffTask "%~1" "%~2" "%~3"
Sign up to request clarification or add additional context in comments.

Comments

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.