Passing batch argument to Choice command
Moderator: DosItHelp
Re: Passing batch argument to Choice command
What does this output exactly tell you? Can you run a certain batch which accepts arguments with that snippet added?
Re: Passing batch argument to Choice command
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.
Re: Passing batch argument to Choice command
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:
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.
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.
-
- Posts: 231
- Joined: 01 Oct 2012 13:32
- Location: Ireland
- Contact:
Re: Passing batch argument to Choice command
Aacini wrote:
Brilliant!
Code: Select all
set "vars=apl1=2,apl2=,apl3=kup,aplN=etc"
set "%vars:,=" & set "%"
Brilliant!
Re: Passing batch argument to Choice command
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:I had not closed the scissors on my snippet.
John A.
All it needed was a context. I gave mine one by changing that last ') else (' to:
Code: Select all
) Else Set "args=%1"
John A.
Re: Passing batch argument to Choice command
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.