How can I implement such a function call (especially how do I work inside the function/procedure with
the received parameter values) ?
The following does NOT work (although I would appreciate to use it in a similar style):
mytest.bat:
set parm1=hello
set parm2=12345
goto mysub %parm1% %parm2%
set parm1=test
set parm2=7777
goto mysub %parm1% %parm2%
...
exit
:MYSUB %1 %2
Echo I got the following parameters: %1 and %2
goback
How do I do this otherwise ?
NT extensions can be used.
Werner
set parm1=hello
set parm2=12345
Call :MYSUB %parm1% %parm2%
set parm1=test
set parm2=7777
Call :MYSUB %parm1% %parm2%
exit /b
:MYSUB
Echo I got the following parameters: %1 and %2
GoTo :EOF
"Werner Sammer" <wer...@yahoo.de> wrote in message
news:44febccd$0$18490$9b4e...@newsspool3.arcor-online.net...
--
Posted via a free Usenet account from http://www.teranews.com
Werner,
You might get some tidier/specific replies to alt.msdos.batch.nt
but since I'm reading this in a comp.os.msdos group I'll give you
a MSDOS solution (which should also work in XP).
mytest.bat:
@echo off
if %1.==[FLAG]. goto mysub
set parm1=hello
set parm2=12345
call %0 [FLAG] %parm1% %parm2%
set parm1=test
set parm2=7777
call %0 [FLAG] %parm1% %parm2%
...
goto END
:MYSUB %1 %2
Echo I got the following parameters: %1 and %2
:END
echo.
"[FLAG]" can be anything you like, just something that is likely
to never be the first real parameter to your batch file.
See if that does what you want.
Pete
--
"We have not inherited the earth from our ancestors,
we have borrowed it from our descendants."
mytest.bat:
-----------
set parm1=hello
set parm2=12345
CALL :mysub %parm1% %parm2%
set parm1=test
set parm2=7777
CALL :mysub %parm1% %parm2%
...
GOTO :EOF
:MYSUB
Echo I got the following parameters: %1 and %2
GOTO :EOF
Note:
CALL :label
the colon is required to specify "internal routine"
MYSUB should not have the %1, %2
%1 and %2 within the routine MYSUB are those passed through the CALL
statement
GOTO :EOF
(the colon is required) is defined in NT+ as "the end of the batch file" and
the label should not be defined within the batch.
(Note here : used to skip over the internal routine code and also at the end
of the routine. This second is merely good practise (IMHO) since it prevents
flow-through to any routine installed AFTER the (in this case) MYSUB
routine.)
>Inside a DOS batch script (in WinXP) I want to call several times a function/procedure.
>This function/procedure should be in the same *.bat batch script as the calling statement
>and take some parameters.
>
>How can I implement such a function call (especially how do I work inside the function/procedure with
>the received parameter values) ?
>
>The following does NOT work (although I would appreciate to use it in a similar style):
>
>
>
>mytest.bat:
>
>set parm1=hello
>set parm2=12345
>goto mysub %parm1% %parm2%
Not "goto" - use call
call :mysub %parm1% %parm2%
>
>set parm1=test
>set parm2=7777
>goto mysub %parm1% %parm2%
Not "goto" - use call
call :mysub %parm1% %parm2%
>
>...
>
>exit
Replace "exit" with
goto :EOF
>
>:MYSUB %1 %2
>
>Echo I got the following parameters: %1 and %2
>
>goback
Remove "goback" and either put the sub last thing in the file, or
terminate it with
goto :EOF
(:EOF is always defined so you don't have to - it's the end of the
file)
--
T.E.D. (tda...@gearbox.maem.umr.edu) Remove "gearbox.maem" to get real address - that one is dead
Although alt.msdos.batch.nt would be better place to ask XP related batch
questions, the key is to use CALL instead of GOTO. Type GOTO/? and CALL/? at
the prompt for details on usage and differences.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
> > NT extensions can be used.
>
> Although alt.msdos.batch.nt would be better place to ask XP related batch
> questions,
Sorry, crosspost and follow-up setting caught me off guard.
For example, ...
parm1=hello
set parm2=12345
call :mysub %parm1% %parm2%
set parm1=test
set parm2=7777
call :mysub %parm1% %parm2%
goto eof:
:MYSUB %1 %2
Echo I got the following parameters: %1 and %2
:: -------- FILE ENDS HERE ---------
Tom Lavedas
============
http://members.cox.net/tglbatch
> Inside a DOS batch script (in WinXP) I want to call several times a function/procedure.
> This function/procedure should be in the same *.bat batch script as the calling statement
> and take some parameters.
>
> How can I implement such a function call (especially how do I work inside the function/procedure with
> the received parameter values) ?
>
Hi Werner,
how about adding a label into the batch file like Sub01 and then using CALL
to re-run the same batch file passing the parameters? You would need to
either also pass an additional parameter to indicate that the batch file
should jump to the required label. So...
if not (%GT%)==() GOTO %GT%
....
Set GT=Sub01
Call SameBat P1 P2 P3
REM Next required to handle return from Call
GOTO End
:Sub01
REM Sub to handle parms.
Instead of using Call you could simple re-run the batch once you have SET a
variable to ensure that it switches control to the correct routine.
Any good? Joker!
You may wish to take a look at these recent postings in an other
thread which gives you "live" examples.
http://www.google.com/groups?selm=edosuc$rus$1%40saavi.uwasa.fi
http://www.google.com/groups?selm=edoqab$q3j$1%40saavi.uwasa.fi
All the best, Timo
--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Useful script files and tricks ftp://garbo.uwasa.fi/pc/link/tscmd.zip