Subscribe to Windows IT Pro
July 22, 2002 12:00 AM

JSI Tip 5535. How can I cause a called batch file to return a call directed environment variable?

Windows IT Pro
InstantDoc ID #76839
Rating: (1)

You can pass a string to a called routine and have it return an environment variable whose name is the string.

Example:

If you wish to determine how many parameters your batch file was passed, and return the results in a environment variable named answer, include the following statement in your batch:

call cntargs answer %*

NOTE: The variable answer need not be defined.

The cntargs batch file could contain:

@echo off
if {%1}

{} @echo Syntax: call cntargs string [arg1 arg2 ... argn]&goto :EOF setlocal set /a numargs=0 :numloop if {%2}

{} endlocal&set /a %1=%numargs%&goto :EOF set /a numargs=%numargs% + 1 shift /2 goto numloop
After the call cntargs answer %* statement, you can use the answer environment variable, as in @echo My batch was passed %answer% parameters.



Related Content:

ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.