Batch file prematurely terminates

Posted on 2009-02-12
Last Modified: 2013-11-10
I have a batch file that runs an xcopy over the network to copy the contents of a harddrive from an older computer to a special folder on the new computer.  It's worked fine until recently it was modified to copy a few other folders over in separate xcopy commands.  Now it does the main xcopy (the first of the three at the bottom), then it stops and doesn't finish after that.

If after it fails to finish everything I need it to, I modify the file to remove everything between the set command and the last two xcopy commands, it will go through fine, so it's not that somethings typed wrong down there.

Does anyone know why it may prematurely terminate the file before finishing all of the xcopy commands?

This is being used with Windows XP.  If you need any more info, just ask :)
Echo off

set /p source="Enter Source Computer Service Tag: "

xcopy "\software\xcopy\exclude.txt" "C:\" /y /e /c /h /i

xcopy "\software\xcopy\xcopy.bat" "C:\Install" /y /e /c /h /i

mkdir "C:\old harddrive"

mkdir "C:\old harddrive\Notesbackup"


cd \old harddrive

xcopy "\\%source%-company\C$\*.*" /y /e /c /h /i /exclude:C:\exclude.txt

xcopy "\\%source%-company\C$\program files\lotus\notes\*.*" "C:\old harddrive\notesbackup\program files\lotus\notes" /y /e /c /h /i

xcopy "\\%source%-company\C$\program files\wherenet\*.*" "C:\program files\wherenet" /y /e /c /h /i


Open in new window

Question by:lizaoreo
    LVL 43

    Accepted Solution

    The bit mentioning xcopy.bat worries me.... if you call it that then it likely to get called instead of xcopy ... can I suggest this is called something else?

    If you remove the echo off from the bbatch file can you post the output it produces please if that isn't it.


    LVL 43

    Expert Comment

    by:Steve Knight
    You haven't got an mkdir.bat or mkdir.cmd too have you?

    Author Comment

    Alright, I'll try removing the xcopy.bat part, it's not really needed anymore anyways.  If that doesn't work I'll come back with the echo off results.

    Nope, no mkdir.bat or mkdir.cmd files.
    LVL 43

    Expert Comment

    by:Steve Knight
    Fair enough.... sorry for asking the seemingly obvious!

    It depends where you run this from but if it is from c:\install or if c:\install is on your path then the second xcopy is copying that batch file into c:\install and then the next xcopy command further down would run xcopy.bat rather than xcopy.exe.

    Anyway as you say give it a try and remove any xcopy.* that are lying around for starters and come back if needed.


    Author Comment

    Alright, I've just started a data transfer today.  It's a long distance transfer though, so it probably won't get done until tomorrow.  Since I don't work on Fridays, it will be Monday before I can get back to you, but I will let you know what happens one way or another.  I do think you're right about the xcopy.bat thing though.  It makes sense and is kind of obvious now that you pointed it out.

    Author Closing Comment

    Thanks, looks like you were right.  After I removed the xcopy.bat file, it worked fine.

    Thanks for your help Dragon
    LVL 43

    Expert Comment

    by:Steve Knight
    No problem, glad it helped.... we've all done it and scratched heads wondering why something doesn't do what you expect...... bat and cmd always run before an exe of the same name...


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    This is an explanation of a simple data model to help parse a JSON feed
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now