1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Help with Batch script that creates a Batch script

Discussion in 'Software Development' started by lancastert, Feb 21, 2008.

Thread Status:
Not open for further replies.
Advertisement
  1. lancastert

    lancastert Thread Starter

    Joined:
    Apr 5, 2007
    Messages:
    9
    I am having a problem with a batch script that prompts a user to enter a set of responses which then set variables - Then the script will call in another batch and writes the output to a new Batch file.

    The problem is the batch file doesn't output the new Batch file the way I intended.

    This is the script I have:

    BEGIN.BAT

    :START
    @ECHO OFF
    CLS
    ECHO.
    ECHO Please enter the full filename reference (e.g. 1-210208)
    ECHO.
    SET REFERENCE=
    SET /P REFERENCE=
    CLS
    ECHO.
    ECHO Please enter the full description (e.g. 12:15 on Thursday 21 FEBRUARY 2008)
    ECHO.
    SET Description=
    SET /P Description=
    CLS
    ECHO.
    ECHO Please enter the date reference (e.g. 210208)
    ECHO.
    SET DTE=
    SET /P DTE=
    CLS
    ECHO.
    ECHO Please enter the reservation slot time (e.g. 1215)
    ECHO.
    SET TME=
    SET /P TME=
    CLS
    ECHO.
    ECHO Please enter the script file you are replacing (e.g. 001)
    ECHO.
    SET Replace=
    SET /P Replace=
    CLS
    ECHO.
    ECHO Please enter the continuing script file (e.g. 002)
    ECHO.
    SET NxtFile=
    SET /P NxtFile=
    CALL "\\hbeu\DfsRoot\GB002\Retail\405447\SYSTEMS\SHARED\INET\ONE\ADMIN\TEMPLATE.CMD">"\\hbeu\DfsRoot\GB002\Retail\405447\SYSTEMS\SHARED\INET\ONE\DATES\%Replace%.BAT"
    CLS
    ECHO.
    ECHO REPLACEMENT OF %Reference% completed!
    PAUSE
    GOTO START

    TEMPLATE.BAT

    ECHO @ECHO OFF
    ECHO CLS
    ECHO IF EXIST "\\hbeu\DfsRoot\GB002\Retail\405447\SYSTEMS\SHARED\INET\ONE\%REFERENCE%.TXT" (
    ECHO GOTO NEXT
    ECHO ) ELSE (
    ECHO GOTO EXIST
    ECHO )
    ECHO :EXIST
    ECHO ECHO.
    ECHO ECHO %DESCRIPTION% IS AVAILABLE
    ECHO ECHO.
    ECHO ECHO Would you like to reserve this time?
    ECHO ECHO.
    ECHO ECHO Yes (Y) or No (N) or Cancel (C)
    ECHO ECHO.
    ECHO :ERROR
    ECHO SET CHOICE=
    ECHO SET /p CHOICE=Enter response to continue (Case sensitive):
    ECHO IF not '%choice%'=='' set choice=%choice:~0,1%
    ECHO IF '%choice%'=='Y' goto YES
    ECHO IF '%choice%'=='N' goto NEXT
    ECHO IF '%choice%'=='C' goto CANCEL
    ECHO ECHO "%choice%" is not valid please try again
    ECHO ECHO.
    ECHO GOTO ERROR
    ECHO :YES
    ECHO ECHO %DESCRIPTION%>>"\\hbeu\DfsRoot\GB002\Retail\405447\SYSTEMS\SHARED\INET\ONE\%REFERENCE%.TXT"
    ECHO ECHO RESERVED BY %FullName%>>"\\hbeu\DfsRoot\GB002\Retail\405447\SYSTEMS\SHARED\INET\ONE\%REFERENCE%.TXT"
    ECHO ECHO LOCATED ON %Team%>>"\\hbeu\DfsRoot\GB002\Retail\405447\SYSTEMS\SHARED\INET\ONE\%REFERENCE%.TXT"
    ECHO ECHO STAFF ID IS %USERNAME%>>"\\hbeu\DfsRoot\GB002\Retail\405447\SYSTEMS\SHARED\INET\ONE\%REFERENCE%.TXT"
    ECHO ECHO "%DATE%","%TIME%","%USERNAME%","%FullName%","%Team%","%DTE%","%TME%">>"\\hbeu\DfsRoot\GB002\Retail\405447\SYSTEMS\SHARED\INET\ONE\LOG\AUDIT.CSV"
    ECHO ECHO.
    ECHO ECHO Thank you %FullName% - Your reservation has been successful.
    ECHO ECHO.
    ECHO PAUSE
    ECHO :NEXT
    ECHO CALL "\\hbeu\DfsRoot\GB002\Retail\405447\SYSTEMS\SHARED\INET\ONE\DATES\002.BAT"
    ECHO :CANCEL

    END

    What am I doing wrong?
     
  2. devil_himself

    devil_himself

    Joined:
    Apr 7, 2007
    Messages:
    4,910
    Try This

    Template.Bat

    Code:
    @ECHO OFF
    CLS
    IF EXIST "\\hbeu\DfsRoot\GB002\Retail\405447\SYSTEMS\SHARED\INET\ONE\%REFERENCE%.TXT " (
    GOTO NEXT
    ) ELSE (
    GOTO EXIST
    )
    :EXIST
    ECHO.
    ECHO %DESCRIPTION% IS AVAILABLE
    ECHO.
    ECHO Would you like to reserve this time?
    ECHO.
    ECHO Yes (Y) or No (N) or Cancel (C)
    ECHO.
    :ERROR
    SET CHOICE=
    SET /p CHOICE=Enter response to continue (Case sensitive):
    IF not '%choice%'=='' set choice=%choice:~0,1%
    IF '%choice%'=='Y' goto YES
    IF '%choice%'=='N' goto NEXT
    IF '%choice%'=='C' goto CANCEL
    ECHO "%choice%" is not valid please try again
    ECHO.
    GOTO ERROR
    :YES
    ECHO %DESCRIPTION%>>"\\hbeu\DfsRoot\GB002\Retail\405447\SYSTEMS\SHARED\INET\ONE\ %REFERENCE%.TXT"
    ECHO RESERVED BY %FullName%>>"\\hbeu\DfsRoot\GB002\Retail\405447\SYSTEMS\SHARED\INET\ONE\%REFERENCE%.TXT"
    ECHO LOCATED ON %Team%>>"\\hbeu\DfsRoot\GB002\Retail\405447\SYSTEMS\SHARED\INET\ONE\%REFERENCE%.TXT"
    ECHO STAFF ID IS %USERNAME%>>"\\hbeu\DfsRoot\GB002\Retail\405447\SYSTEMS\SHARED\INET\ONE\%REFERENCE%.TXT"
    ECHO "%DATE%","%TIME%","%USERNAME%","%FullName%","%Team%","%DTE%","%TME%">>"\\hb eu\DfsRoot\GB002\Retail\405447\SYSTEMS\SHARED\INET\ONE\LOG\AUDIT.CSV"
    ECHO.
    ECHO Thank you %FullName% - Your reservation has been successful.
    ECHO.
    PAUSE
    :NEXT
    CALL "\\hbeu\DfsRoot\GB002\Retail\405447\SYSTEMS\SHARED\INET\ONE\DATES\002.BAT"
    :CANCEL
    
     
  3. lancastert

    lancastert Thread Starter

    Joined:
    Apr 5, 2007
    Messages:
    9
    Thanks for your response but I need the "ECHO ECHO" to remain so when the file is output it has the "ECHO" command to remain?

    Is this possible?
     
  4. devil_himself

    devil_himself

    Joined:
    Apr 7, 2007
    Messages:
    4,910
    Does The Above Script Work By Removing The Double "Echo Echo" Statements ?
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/685664

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice