+ Post New Thread
Results 1 to 10 of 10
Scripts Thread, Run a .bat followed by another on completion in Coding and Web Development; I have a batch file that is set to copy a large quantity of files from a network share, but ...
  1. #1
    techtopia's Avatar
    Join Date
    Jul 2010
    Posts
    89
    Thank Post
    27
    Thanked 18 Times in 6 Posts
    Rep Power
    44

    Run a .bat followed by another on completion

    I have a batch file that is set to copy a large quantity of files from a network share, but I want to run another batch file immediately after the first one finishes but with files from another network location.

    At present I have...

    xcopy \\EARTH\usbdisk2\Movies S:\Movies\ /E /F /K /J

    ....in one batch file, and an identical command in another batch file (just a different source location)

    How can I achieve what I need to do please? I intend to run these as scheduled tasks when a user logs off from a workstation. i.e overnight.

  2. #2

    witch's Avatar
    Join Date
    Nov 2005
    Location
    Dorset
    Posts
    11,371
    Thank Post
    1,499
    Thanked 2,579 Times in 1,795 Posts
    Rep Power
    775
    Having found out how long the first one takes, can you not just schedule them both so that the second one starts as near to the completion of the first one as you can?
    Or is that not do-able?

  3. #3


    Join Date
    Feb 2007
    Location
    Northamptonshire
    Posts
    4,701
    Thank Post
    352
    Thanked 805 Times in 720 Posts
    Rep Power
    348
    CALL file2.bat

  4. Thanks to kmount from:

    techtopia (17th August 2010)

  5. #4

    witch's Avatar
    Join Date
    Nov 2005
    Location
    Dorset
    Posts
    11,371
    Thank Post
    1,499
    Thanked 2,579 Times in 1,795 Posts
    Rep Power
    775
    ..or do what he says...

  6. #5


    Join Date
    Feb 2007
    Location
    Northamptonshire
    Posts
    4,701
    Thank Post
    352
    Thanked 805 Times in 720 Posts
    Rep Power
    348
    Of course, is there no reason you couldn't put the two of them in the same batchfile?

  7. Thanks to kmount from:

    techtopia (17th August 2010)

  8. #6
    techtopia's Avatar
    Join Date
    Jul 2010
    Posts
    89
    Thank Post
    27
    Thanked 18 Times in 6 Posts
    Rep Power
    44
    Quote Originally Posted by witch View Post
    Having found out how long the first one takes, can you not just schedule them both so that the second one starts as near to the completion of the first one as you can?
    Or is that not do-able?
    I am going to be copying almost 90GB of data over the network in the first batch, slightly less in the second round, so guesswork isn't really an option at this stage.

  9. #7
    techtopia's Avatar
    Join Date
    Jul 2010
    Posts
    89
    Thank Post
    27
    Thanked 18 Times in 6 Posts
    Rep Power
    44
    Quote Originally Posted by kmount View Post
    CALL file2.bat
    I place that at the end of the 1st batch I presume, which will then run the 2nd?
    Or as you mention further down, put them in the same file - I wasn't sure about this when I though of that; I definitely don't want them running together, so I didn't try it. They would definitely run one after the other if they were in the same file? Any sort of 'separator' needed?

  10. #8
    rh91uk's Avatar
    Join Date
    Sep 2008
    Location
    UK
    Posts
    877
    Thank Post
    137
    Thanked 132 Times in 114 Posts
    Rep Power
    36
    Quote Originally Posted by techtopia View Post
    I place that at the end of the 1st batch I presume, which will then run the 2nd?
    Or as you mention further down, put them in the same file - I wasn't sure about this when I though of that; I definitely don't want them running together, so I didn't try it. They would definitely run one after the other if they were in the same file? Any sort of 'separator' needed?
    I would put them one after the other in the same file. No seperator needed, CMD will run the first line then the second line - one after the other.
    You could always just add a "pause" at the end to check that the commands have run correctly without any errors before the batch file exits.

  11. Thanks to rh91uk from:

    techtopia (17th August 2010)

  12. #9


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,635
    Thank Post
    250
    Thanked 2,909 Times in 2,141 Posts
    Rep Power
    829
    You can even do the following where the second command will only run if the first was successful.

    Code:
    xcopy \\EARTH\usbdisk2\Movies S:\Movies\ /E /F /K /J && xcopy \\SUN\usbdisk2\Movies S:\Movies\ /E /F /K /J

    Personally, whenever I have to copy a huge amounts of data I use RoboCopy. It has more options than XCopy e.g. it can log everything to a text file so you can make sure nothing was missed, and the latest version can use more than one thread which will make the file transfer take a lot less time.
    Last edited by Arthur; 17th August 2010 at 11:23 PM.

  13. Thanks to Arthur from:

    techtopia (18th August 2010)

  14. #10
    somabc's Avatar
    Join Date
    Oct 2007
    Location
    London
    Posts
    2,337
    Thank Post
    83
    Thanked 388 Times in 258 Posts
    Rep Power
    112
    SS64 is a good resource for useful command line tools

    Call


    Call one batch program from another.

    Syntax
    CALL [drive:][path]filename [parameters]

    CALL :label [parameters]

    CALL internal_cmd

    Key:
    pathname The batch program to run

    parameters Any command-line arguments

    :label Jump to a label in the current batch script.

    internal_cmd Any internal command, first expanding any variables in the argument
    You could also use start /wait to start other files such as cmd etc.

    Start - Start a program

    Start a specified program or command in a separate window.

    Syntax
    START "title" [/Dpath] [options] "command" [parameters]

    Key:
    title : Text for the CMD window title bar (required)
    path : Starting directory
    command : The command, batch file or executable program to run
    parameters : The parameters passed to the command

    Options:
    /MIN : Minimized
    /MAX : Maximized
    /WAIT : Start application and wait for it to terminate
    /LOW : Use IDLE priority class
    /NORMAL : Use NORMAL priority class
    /HIGH : Use HIGH priority class
    /REALTIME : Use REALTIME priority class

    /B : Start application without creating a new window. In this case
    ^C will be ignored - leaving ^Break as the only way to
    interrupt the application
    /I : Ignore any changes to the current environment.

    Forcing a Sequence of Programs
    If you require your users to run a sequence of 32 bit GUI programs to complete a task, create a batch file that uses the start command:

    @echo off
    start /wait /b First.exe
    start /wait /b Second.exe
    start /wait /b Third.exe

    Create a shortcut to this batch file and place it on the Start menu or desktop. Set it to run minimized.
    When the user double-clicks the shortcut, <First.exe> runs.
    When <First.exe> terminates, <Second.exe> runs
    When <Second.exe> terminates, <Third.exe> runs
    Robocopy

    Syntax
    ROBOCOPY source_folder destination_folder [file(s)_to_copy] [options]
    Last edited by somabc; 18th August 2010 at 12:08 AM.

  15. Thanks to somabc from:

    techtopia (18th August 2010)



SHARE:
+ Post New Thread

Similar Threads

  1. [SIMS] Reset the completion status of marksheets?
    By LosOjos in forum MIS Systems
    Replies: 5
    Last Post: 26th May 2010, 01:21 PM
  2. Run Fat Boy Run
    By WOW_freak in forum General Chat
    Replies: 2
    Last Post: 12th August 2009, 11:42 AM
  3. Shutdown.bat
    By Mr.Ben in forum Windows
    Replies: 9
    Last Post: 8th May 2009, 10:37 AM
  4. GPO .bat won't run
    By skenmy in forum Wireless Networks
    Replies: 3
    Last Post: 16th April 2009, 09:25 AM
  5. The Bat
    By Dos_Box in forum General Chat
    Replies: 1
    Last Post: 11th July 2008, 02:19 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •