Search code examples
windowsbatch-filecmdcommandcall

Windows cmd bat call command with /?


I understand that

=> call /?

will show the help message for the call command. But

=> call SubBatch params /?

Also shows the help message, either at the command prompt or within a bat file.

This can be annoying if i have a bat file that calls another bat file, but the user invoked the first bat file with /? somewhere in the linend Eg. if i have a batch file named main.bat containing:

echo Starting my batch file
call SubBatch %*

If i invoke "main p1 p2 /?" or "main abc/?def" I get the call help text. I can avoid this (ie. seeing the call help) by putting the string containing the /? in quotes: "/?" or "abc/?def" but that string could be anywhere in the param string %*

Are there other way to handle this?

I would like

=> call sub params /? params

should call the sub and not show the call help msg.


Solution

  • You could use the CALL late percent expansion, then the CALL command doesn't detect the /?. Btw. It also has the advantage of less modifying arguments.

    @echo off
    
    set "args=%*"
    call %%args%%
    

    Examples

    myBatch.bat echo This is a test /?
    myBatch.bat echo /? Show help for the ECHO command