locked
Call a batch file from another batch file; files are not copied RRS feed

  • Question

  • Hi Guys, i'm trying to call a batch file from a batch file. The call is working but the commands inside the batch files are not working but the commands are working when i launch the batch file individually.

    Batch1 to call Batch2

    Batch1:

    set clean==false
    
    IF /I "%continue%"=="standalone" goto StandAlone
    
    :StandAlone
    Call "DoNotEnterHere\Batch2.bat"
    goto again

    Batch2:

    @echo off
    cls
    echo press any key to continue
    pause 
    
    xcopy  /s /q PT6\Tingoo*.xml "C:\Pixel \Res\" /Y
    xcopy  /s /q Tomo\Fw_Settings*.xml C:\SLAB\\Res\ /Y
    
    echo files copied
    pause
    I'm getting a message 0 files copied, again when i run the Batch2.bat file, files are copied successfully.

    How can i fix this?

    Thank you


    • Edited by FF_DAPI Sunday, March 29, 2015 10:01 AM added
    Sunday, March 29, 2015 9:59 AM

Answers

  • I note that you're not dealing with the errors I pointed out.

    Why not keep it simple and put both scripts into the same batch file like so:

    @echo off
    if "%x%"=="yes" call :Batch2
    rem More code goes here
    goto :eof

    :Batch2
    rem Here are the lines for Batch2

    In this way you have the whole script in one file and you do not need to worry about paths.

    • Marked as answer by FF_DAPI Sunday, March 29, 2015 12:50 PM
    Sunday, March 29, 2015 12:38 PM

All replies

  • Your batch files contain several errors.

    Batch File 1
    set clean==false
    should be
    set clean=false

    IF /I "%continue%"=="standalone" goto StandAlone
    The variable %continue% is not defined.

    Call "DoNotEnterHere\Batch2.bat"
    In batch files you must fully qualify all external files by adding a drive letter and a path.

    goto again
    The label "again" is not defined.

    Batch File 2
    xcopy  /s /q PT6\Tingoo*.xml "C:\Pixel \Res\" /Y
    The folder PT6 needs a drive letter and a path.

    xcopy  /s /q Tomo\Fw_Settings*.xml C:\SLAB\\Res\ /Y
    The folder Tomo needs a drive letter and a path.
    Change "Slab\\" to "Slab\".

    Sunday, March 29, 2015 10:18 AM
  • @Frederick Long, thank you for the reply.

    This is the complete code, for Batch1.bat:

    @ECHO OFF
    
    :Main
    cls
    echo This will launch specific batch file  
    echo to help configure your system.
    echo Please pick an option to configure:
    echo.
    set /p continue=(standalone/sts/exit):
    set clean==false
    
    IF /I "%continue%"=="standalone" goto StandAlone
    IF /I "%continue%"=="sts" goto PcClinet
    
    :StandAlone
    Call %0\..\DoNotEnterHere\StandAlone\Batch2.bat
    goto again
    
    :again
    cls
    echo Does anything else need to be configured?
    set /p repeat=(y/n):
    IF /I "%repeat%"=="y" goto Main
    IF /I "%repeat%"=="n" goto exit
    IF /I "%repeat%" NEQ "y" goto error
    IF /I "%repeat%" NEQ "n" goto error
    
    :exit
    exit
    
    :ERROR
    echo.
    echo Invalid option. Press any key to retry.
    pause > nul
    goto Main

    Batch2.bat code:

    @echo off
    cls
    echo press any key to continue
    pause 
    
    xcopy  /s /q PT6\Tingoo*.xml "C:\Pixel \Res\" /Y
    xcopy  /s /q Tomo\Fw_Settings*.xml "C:\SLAB\Res\" /Y
    
    echo files copied
    pause

    I'm having the same problem.

    How can i execute without giving the full path? because i would like to place this file anywhere from the system.

    DoNotEnterHere contains both Btach1/StandAlone/Batch2.bat

    Thank you for your support.



    • Edited by FF_DAPI Sunday, March 29, 2015 11:05 AM added
    Sunday, March 29, 2015 10:54 AM
  • OK, here are a few more comments:

    set /p continue=(standalone/sts/exit):
    IF /I "%continue%"=="standalone" goto StandAlone
    IF /I "%continue%"=="sts" goto PcClinet
    :StandAlone
    When the user types exit then the batch file continues with Standalone. It does not go to Exit.
    Same for a blank reply or for any reply other than "sts". You must catch all possible user input!

    Call %0\..\DoNotEnterHere\StandAlone\Batch2.bat
    %0 returns the name of the current batch file, e.g. Batch1.bat. To see what I mean, open a Command Prompt with cmd.exe, then do some debugging of your own by changing the line like so:

    echo Call %0\..\DoNotEnterHere\StandAlone\Batch2.bat
    goto :eof

    Sunday, March 29, 2015 11:12 AM
  • Sorry, it's confusing for me.

    The Folder "DoNotEnterHere" contains the batch file 'Batch1.bat' and also the "StandAlone" folder, the StandAlone folder contains 'Batch2.bat'.

    'Batch2.bat' works when i launch it individually.

    When i call the 'Batch2.bat' via Batch1.bat, it's not working. I understand that we need to give the full path...

    Is there any way to bypass & execute the 'Batch2.bat'. file successfully?

    Thank you

    Sunday, March 29, 2015 11:40 AM
  • I note that you're not dealing with the errors I pointed out.

    Why not keep it simple and put both scripts into the same batch file like so:

    @echo off
    if "%x%"=="yes" call :Batch2
    rem More code goes here
    goto :eof

    :Batch2
    rem Here are the lines for Batch2

    In this way you have the whole script in one file and you do not need to worry about paths.

    • Marked as answer by FF_DAPI Sunday, March 29, 2015 12:50 PM
    Sunday, March 29, 2015 12:38 PM
  • Thanks for your help, it'w working.
    Sunday, March 29, 2015 12:51 PM