1

What I mean by that, is for example, if a file is to be moved to a directory, and the next line of code assumes the file is there and tries to open it, but the move itself is not finished, resulting in an error? Like needing to include ping localhost -n 5 between two commands?

3
  • 1
    Well if the file is like 4GB then yes, It cannot open the file if its still transferring. A way is to use ping 127.0.0.1 -n 6 > nul Ofcourse 4GB will take longer than 5 seconds. DOS does not wait for 1 command to finish.
    – Dylan_R
    Commented Oct 5, 2016 at 14:16
  • Ok that is what I was wondering, if it checks whether or not a command is finished before going on to the next
    – Daniel
    Commented Oct 5, 2016 at 14:19
  • Nope Dos will not wait for 1 command to finish. You probably then have to use If else statements If xx file exists - go to. you get the idea.
    – Dylan_R
    Commented Oct 5, 2016 at 14:20

1 Answer 1

4

If you use a regular batch, and don't implement START or alike to spawn new processes, then it will wait for the previous command to finish before continuing.

Batch won't advance to the next command until it receives an exit code from the previous command. So in the context of a basic file copy, it will wait for the copy command to complete. You can witness this by simply running a Copy command from the command prompt; it won't give you the prompt back until it's done copying.

Now, where you may run into trouble is when you launch a program that spawns new processes that do work that you need to wait for.

For example, the launcher program may exit (returning an exit code to the batch file, causing it to continue on) before the new process it started finishes doing what you need done before continuing the batch.

In those cases you'll need to either pause the batch file for an amount of time (and hope that it finishes within that time), or use a loop in the batch to monitor for the process to finish (ie: with tasklist) before continuing.

1
  • Very well explained
    – Daniel
    Commented Oct 5, 2016 at 16:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .