Mittwoch, 28. November 2007

BATCH_ Create libraries with valuable Batch subroutines

If you write some Batch subroutines that make common stuff like calculating the string length or testing for a number, you don't want to copy&paste these into each script that needs these. Be cool, there is a very easy solution how you can bundle all of your helper subroutines into one (or even more) files. Just copy them into an empty file, and add the following code at the very first line:
SHIFT /1 & GOTO %~1

That jumps to the label you provided as the first parameter after shifting all remaining parameters one down leaving %0 as it is.

Let's say you saved that file as C:\Windows\lib.cmd. Now you can call any subroutine from another script by issuing
CALL %SystemRoot%\lib.cmd :MY_SUBROUTINE param1 param2 ...

Remember to enable extensions and delayed variable expansion in each of your subroutines when needed - you cannot depend on the "frame" script's setting any more!
:MY_SUBROUTINE
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
... routine here ...
ENDLOCAL
GOTO :EOF

Reflog

Informationstechnische Howtos, Hinweise und Merkwürdiges

Batchlib v1.0 2008-03-29

Aktuelle Beiträge

HOWTO_ O2 DSL Surf &...
Der O2 DSL Surf & Phone-Router ist für die alleinige...
cypressor - 12. Feb, 19:57
Uptweak Windows XP Home...
There are a lot of annoying limitations in Windows...
cypressor - 9. Okt, 19:30
BATCHLIB_ Batchlib package...
Download Batchlib package v1.0 (5 KB zip file) What...
cypressor - 29. Mär, 19:10
BATCHLIB_ Batchlib library...
The batchlib library string.cmd is part of the batchlib...
cypressor - 29. Mär, 18:10

Homepage Ticker

Links

Status

Online seit 6784 Tagen
Zuletzt aktualisiert: 28. Jun, 11:32
RSS XML 1.0 Button-Get-Firefox

batch
batchlib
howto
tech
video
Profil
Abmelden
Weblog abonnieren