Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batches as Functions  (Read 2583 times)

0 Members and 1 Guest are viewing this topic.

yossi_moses

    Topic Starter


    Greenhorn

    • Experience: Beginner
    • OS: Unknown
    Batches as Functions
    « on: June 29, 2015, 05:05:55 AM »
    I thout about seperating code between files and use them as functions.
    I had many errors until I realized that the Output of this Funcs must be only the 'ECHO ...' that I need.
    In these file there must be @ECHO OFF in its 1st line, otherwise each line code become an Output.
    Here is a little example. even recursive:
    Let's have file Named Func.CMD
    We call it from Command-Line with a parameter:
    Code: [Select]
    CALL Func.CMD 1The code in Func.CMD:
    Code: [Select]
    @ECHO OFF
    SET /A X = %1 + 1
    IF %X% LSS 10 FOR /F "DELIMS=" %%i IN ('CALL Func.CMD %X%') DO SET /A X = %%i
    ECHO %X%

    It looks so:
    C:\>CALL Func.CMD 1
    10

    I hope someone can enjoy it
    Yossi

    Lemonilla



      Apprentice

    • "Too sweet"
    • Thanked: 70
    • Computer: Specs
    • Experience: Experienced
    • OS: Windows 7
    Re: Batches as Functions
    « Reply #1 on: July 23, 2015, 05:38:27 PM »
    This can be useful, but its hard to pass things out.

    Something like this might work.
    Code: [Select]
    Setlocal enabledelayedexpansion
    Set param_num=0
    For %%a in ('call func.bat %param1%') do (
    Set param_!param_num!=%%a
    Set /a param_num+=1
    )
    Quote from: patio
    God Bless the DOS Helpers...
    Quote
    If it compiles, send the files.