Discussion forum for all Windows batch related topics.
- Posts: 44
- Joined: 05 Apr 2019 05:52
In abc.bat, define a subroutine func1. In func1, get valOfI and valOfO from command line. Order of “-i valOfI” and “-o valOfO” can be any in command line.
- Posts: 2243
- Joined: 12 Feb 2011 21:02
- Location: United States (east coast)
Batch does not have any built in functionality for named arguments. You will need batch code to parse named arguments and store the values in environment variables. Once you have that, you can do anything you want with the values, including pass them to called functions. Things to consider:
- How to handle invalid options
- What are default values if named arguments are not provided
- Do you also have or want unnamed (positional) arguments?
Have a look at my StackOverflow answer
to a question about Windows Bat file optional argument parsing. I frequently use some variant of that technique in many of my own scripts to great effect.