misgre.blogg.se

Dos prompt
Dos prompt












dos prompt

Using parameters in batch files: %0 and %9īatch files can refer to the words passed in as parameters with the tokens: %0 to %9.

dos prompt

You can view the full range of these capabilities by typing CALL /? in the command prompt. To get the path of the directory where the batch file was launched from (very useful!) you can use ECHO %~dp0

dos prompt

This functionality is accessed with constructs that begin with %~.įor example, to get the size of the file passed in as an argument use ECHO %~z1 Substitution of batch parametersįor parameters that represent file names the shell provides lots of functionality related to working with files that is not accessible in any other way. This scheme allows you to parse pretty complex command lines without going insane. A good way to parse the command line in such cases is :parse For example, a script may recognize the flags -a and -b in any order. SHIFT is also useful when you want to easily process parameters without requiring that they are presented in a specific order. %9 takes the value of the tenth argument (if one is present), which was not available through any variable before calling SHIFT (enter command SHIFT /? for more options). This command shifts the values of all arguments one place, so that %0 takes the value of %1, %1 takes the value of %2, etc. If you need to access more than 9 arguments you have to use the command SHIFT. Handling more than 9 arguments (or just making life easier) Note the tilde character which causes any surrounding quotes to be removed from the value of %1 without a tilde you will get unexpected results if that value includes double quotes, including the possibility of syntax errors. This is done with constructs like IF "%~1"="", which is true if and only if no arguments were passed at all. There are also lots of important techniques to be aware of in addition to simply how to access the parameters.

dos prompt

  • %* is all parameters specified in the command line - this is very useful if you want to forward the parameters to another program.
  • %0 is the executable (batch file) name as specified in the command line.
  • There are also two other tokens that you can use: As others have already said, parameters passed through the command line can be accessed in batch files with the notation %1 to %9.














    Dos prompt