Swap Functions (in an include file)

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
lorus
Posts: 2
Joined: 20 Jan 2010 03:44

Swap Functions (in an include file)

#1 Post by lorus » 20 Jan 2010 03:53

Hi there,

as described here I created a huge amount of functions for my daily uses.

I use this functions in many scripts, so my question is if there is a smarter way then copy+paste the functions at the end of each single script.

Something like swapping all functions in a "functions.cmd" and include this "functions.cmd" in every script, so that I can access the functions.

Is something like that possible?

Thanks in Advance

Lorus

P.S. dostips.com is impressive and helped me very much so far :-)

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

#2 Post by alan_b » 20 Jan 2010 15:46

Firstly, you can use

Code: Select all

CALL :FUNCTION1 arg2 arg3 etc  

That will look for and call the label FUNCTION1

You can have lots of such functions, all with more meaningful names.
You quite possible already have this.

Unlike 'C' compilers, batch scripts do not support the #include MyFunctions.
Almost equivalent is to create Functions.cmd and start with GOTO %1,
and then append all your functions.
Then your "little scripts" will simply invoke

Code: Select all

CALL Functions.cmd FUNCTION1 arg2 arg3 etc 


Note, you can choose to pass arguments to your function on the command line, or you can pass them via environmental variables.
Your function may be able to return values via environmental variables, but I vaguely remember some difficulties.

Alan

lorus
Posts: 2
Joined: 20 Jan 2010 03:44

#3 Post by lorus » 21 Jan 2010 03:05

So there's no "clean" solution for it, I worried that, but anyway thanks for your reply :-)

Post Reply