Adding command-line switches to a batch file - Microsoft Windows

This is a discussion on Adding command-line switches to a batch file - Microsoft Windows ; Hi all, I have written a little batch file (.bat) which I would like to print out usage information and exit if supplied with (say) a /? or /h switch. Now I know how to grab parameters from the command ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Adding command-line switches to a batch file

  1. Adding command-line switches to a batch file

    Hi all,

    I have written a little batch file (.bat) which I would like to print
    out usage information and exit if supplied with (say) a /? or /h
    switch. Now I know how to grab parameters from the command line using
    %1 etc, but I can't find a way handle switches. Is this possible?

    btw, this is under Windows XP and I have been using the reference:
    http://www.microsoft.com/resources/d...-us/batch.mspx


  2. Re: Adding command-line switches to a batch file

    Trevor Hills wrote:
    > Hi all,
    >
    > I have written a little batch file (.bat) which I would like to print
    > out usage information and exit if supplied with (say) a /? or /h
    > switch. Now I know how to grab parameters from the command line using
    > %1 etc, but I can't find a way handle switches. Is this possible?
    >
    > btw, this is under Windows XP and I have been using the reference:
    >

    http://www.microsoft.com/resources/d...-us/batch.mspx

    probably best to ask in news:alt.msdos.batch.nt

    the way I'd do it in standard DOS is

    @echo off
    if #%1==#/? goto usage
    if #%1==#/h goto usage
    if #%1==#/H goto usage
    echo main program here
    rem ....
    goto exit
    :usage
    echo %0 is an example batch program to demonstrate usage
    echo Usage is %0 {/?!/h!/H}
    :exit



    :exit



+ Reply to Thread