Page 1 of 1

Swap Functions (in an include file)

Posted: 20 Jan 2010 03:53
by lorus
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 :-)

Posted: 20 Jan 2010 15:46
by alan_b
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

Posted: 21 Jan 2010 03:05
by lorus
So there's no "clean" solution for it, I worried that, but anyway thanks for your reply :-)