Passing batch argument to Choice command

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
sambul35
Posts: 192
Joined: 18 Jan 2012 10:13

Re: Passing batch argument to Choice command

#16 Post by sambul35 » 27 Apr 2016 11:30

What does this output exactly tell you? :?: Can you run a certain batch which accepts arguments with that snippet added?

thefeduke
Posts: 211
Joined: 05 Apr 2015 13:06
Location: MA South Shore, USA

Re: Passing batch argument to Choice command

#17 Post by thefeduke » 27 Apr 2016 12:12

sambul35 wrote:What does this output exactly tell you? :?: Can you run a certain batch which accepts arguments with that snippet added?

I did not add it to anything. I just ran the "snippet" itself, as posted. I called the one that I posted 'Arg2Choices.bat' and the output was:

Code: Select all

C:\Users\Zani\Scripts>arg2choices
Do you want to enter batch arguments? Y/N [color=#FF0040]N[/color]
Going nowhere....

C:\Users\Zani\Scripts>arg2choices gogo
keep going....

C:\Users\Zani\Scripts>arg2choices
Do you want to enter batch arguments? Y/N Y

Batch arguments:[color=#FF0040]fighting words[/color]

M:\Packages\DamageControl.bat fighting words

C:\Users\Zani\Scripts>

The script just Echoed the .bat filename and the reply that I gave as the arguments. What's to conclude? In my environment, one went through a choice process and the other did not. I made one kind of change. Perhaps a different kind of change would work for both.
John A.

sambul35
Posts: 192
Joined: 18 Jan 2012 10:13

Re: Passing batch argument to Choice command

#18 Post by sambul35 » 27 Apr 2016 12:27

Thanks for your input. Below is a shorter version of my snippet tested in Win10, it must be run from a batch one wants to restart with arguments:

Code: Select all

@echo off
setlocal EnableExtensions EnableDelayedExpansion
set "mes1=Do you want to enter batch arguments? Y/N"
set "mes2=Batch arguments:"

if "%1"=="" (
   choice /c yn /n /m "%mes1%" /t 10 /d n
   if !errorlevel! equ 1 (
      echo/ & set /p "args=%mes2% > "
      if defined args (%~f0 !args!))
) else (...

If you want to run this snippet standalone, replace %~f0 with your batch full path & name. If someone can offer a short universal code that works in any Windows version that would be great.
Last edited by sambul35 on 29 Apr 2016 21:58, edited 1 time in total.

Sponge Belly
Posts: 231
Joined: 01 Oct 2012 13:32
Location: Ireland
Contact:

Re: Passing batch argument to Choice command

#19 Post by Sponge Belly » 27 Apr 2016 13:48

Aacini wrote:

Code: Select all

set "vars=apl1=2,apl2=,apl3=kup,aplN=etc"
set "%vars:,=" & set "%"


Brilliant! 8)

thefeduke
Posts: 211
Joined: 05 Apr 2015 13:06
Location: MA South Shore, USA

Re: Passing batch argument to Choice command

#20 Post by thefeduke » 27 Apr 2016 17:37

Not to worry about self-inflicted wounds. This construct works just fine with Win7 and always did.
All it needed was a context. I gave mine one by changing that last ') else (' to:

Code: Select all

) Else Set "args=%1"
I had not closed the scissors on my snippet.
John A.

sambul35
Posts: 192
Joined: 18 Jan 2012 10:13

Re: Passing batch argument to Choice command

#21 Post by sambul35 » 03 May 2016 22:19

On alternative note, if a series of batch arguments is added with SET /P command, what would be an effective way to automatically separate them with delimiters while adding or right after? Each argument can be a letters, word, or 1-2 digits number, and a resulting series of arguments can consist of a mix of these types.

Post Reply