input variables

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
skaliam
Posts: 8
Joined: 23 Jul 2012 12:09

input variables

#1 Post by skaliam » 12 Aug 2012 12:47

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

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: input variables

#2 Post by aGerman » 12 Aug 2012 12:58

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

skaliam
Posts: 8
Joined: 23 Jul 2012 12:09

Re: input variables

#3 Post by skaliam » 12 Aug 2012 13:07

WOW worked treat! Thank you.

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

Post Reply