Page 1 of 1

input variables

Posted: 12 Aug 2012 12:47
by skaliam
Hi,
Just wondering if there is a way to have input from a command line to a script for when it is run
so say in the batch file there is a SET /P option=select option:
but is there a way that the variable can be set when the script is run so something like:
C:\batfile.bat 2

Re: input variables

Posted: 12 Aug 2012 12:58
by aGerman
Arguments come in as %1, %2 ... %9.
Perhaps that is what you're looking for:

Code: Select all

@echo off
if "%~1"=="" (
  set /p "option=select option: "
) else (
  set "option=%~1"
)

Either the batch file was called with an argument or the user will be prompted for an input.

Regards
aGerman

Re: input variables

Posted: 12 Aug 2012 13:07
by skaliam
WOW worked treat! Thank you.

I have only just started teaching myself but this will help me loads!
Thank you again