1

Is there any straightforward way to call a .bat file and have it prompt me for each of the arguments that will replace the %1 %2 and so forth fields? I can memorize their order just fine and run it from the command line, but it would be preferable for friends & family if there was an icon they could just click and get the appropriate prompts.

6
@echo off
echo "Parameter 1" 
set /p p1=
echo "Parameter 2"
set /p p2=
[...]
yourcommand.exe %p1% %p2% [...]

@echo off stops commands being printed. We will ask for a parameter each using echo, set /p p1= asks the user for some input (use "return" or "enter" to confirm) and stores it into variable %p1%. In the last line you can call your program with the parameters entered.

3
  • Could you provide some explanation about what your code does? Especially the set statements. Oct 31 '11 at 13:18
  • set just asks for some input and stores it into a variable.
    – Jens Erat
    Oct 31 '11 at 15:46
  • As a note, at least for some versions of windows (I haven't tested) the set commands can be simplified to set /p pn="Parameter n: " Mar 23 '12 at 15:31
2

You can ask the user for parameters with set /p.

Optionally, you can check if %1 exists first. e.g. with if "%1"=="" or something similar.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.