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

Author Topic: PASSING VARIABLES BETWEEN BAT FILES  (Read 3123 times)

0 Members and 1 Guest are viewing this topic.

BRIANH

    Topic Starter


    Rookie

    • Experience: Familiar
    • OS: Windows XP
    PASSING VARIABLES BETWEEN BAT FILES
    « on: January 04, 2017, 03:27:32 PM »
    I'm attempting to execute a bat file which sets a variable and then have that
    variable available to a second bat file. So I set up a test..
    TEST0-BAT.BAT RUNS  TEST1-BAT.BAT WHICH IN TURN RUNS TEST2-BAT.BAT

    My issue is I'm not getting anything in TEST1-BAT for the variable - Timestamp3
    which is set in TEST2-BAT.BAT. The echo stmts. in TEST2-BAT appear to show all
    variables are set correctly,

    I'm running WIN. 10 XP.

    Anyone have any ideas / advice ?

    thanks


    TEST0-BAT CONTAINS:
       TEST1-BAT.BAT > TEST1-BAT.OUT 2> TEST1-BAT.ERR

    TEST1-BAT.BAT CONTAINS:
       TEST2-BAT    > TEST2-BAT.OUT 2> TEST2-BAT.ERR
       @FOR /F "tokens=*" %%i IN ('TEST2-BAT.bat') DO set Timestamp3=%%i
       echo %Timestamp3%
       ren testX.txt "TESTX-%Timestamp3%.txt"

       
    TEST2-BAT CONTAINS:
       @echo off
       cls
       echo Date format = %date%
       set "dd=%date:~7,2%"
       set "mm=%date:~4,2%"
       set "yyyy=%date:~10,4%"
       echo.
       echo Time format = %time%
       set "hh=%time:~0,2%"
       set "min=%time:~3,2%"
       set "ss=%time:~6,2%"
       echo.
       echo Timestamp1 = %date:~7,2%_%date:~4,2%_%date:~10,4%-%time:~0,2%_%time:~3,2%_%time:~6,2%

       echo Timestamp2 = %date:~7,2%-%date:~4,2%-%date:~10,4%-%time:~0,2%_%time:~3,2%_%time:~6,2%

       set Timestamp3=%dd%-%mm%-%yyyy%_%hh%-%min%-%ss%

       echo Timestamp3 = %Timestamp3%

    patio

    • Moderator


    • Genius
    • Maud' Dib
    • Thanked: 1769
      • Yes
    • Experience: Beginner
    • OS: Windows 7
    Re: PASSING VARIABLES BETWEEN BAT FILES
    « Reply #1 on: January 04, 2017, 03:37:42 PM »
    Fix your capslock 1st...
    " Anyone who goes to a psychiatrist should have his head examined. "

    Squashman



      Specialist
    • Thanked: 134
    • Experience: Experienced
    • OS: Other
    Re: PASSING VARIABLES BETWEEN BAT FILES
    « Reply #2 on: January 04, 2017, 06:23:54 PM »
    How about using the BB code tags.

    BRIANH

      Topic Starter


      Rookie

      • Experience: Familiar
      • OS: Windows XP
      Re: PASSING VARIABLES BETWEEN BAT FILES
      « Reply #3 on: January 05, 2017, 03:38:04 PM »
      I'm fairly new to DOS..... so I have no idea what your reference to 'fix your capslock 1st'  means...

      Be that as it may... I've done more testing and have solved my issue... thanks

      Salmon Trout

      • Guest
      Re: PASSING VARIABLES BETWEEN BAT FILES
      « Reply #4 on: January 05, 2017, 03:45:54 PM »
      I have no idea what your reference to 'fix your capslock 1st'  means...
      He means it is bad manners to type all in capital letters, as you did in the thread title. Doing that is the web equivalent of shouting (e.g. for attention). This has been so for around 20 years if not more.