6

Can someone please explain what's the difference between

call someBatchFile.bat ...

And

cmd /C someBatchFile.bat ...

They both were suggested to me as solutions tothis problem, but I don't understand why they both work, and more importantly, if there are any significant differences I must be aware of.

askedAug 20, 2016 at 14:42
carlossierra's user avatar
3
  • 2
    Second statement starts a new process, any changes that someBatchFile.bat makes to environment variables won't affect and won't be visible to your current batch file. Could be good, could be bad.CommentedAug 20, 2016 at 15:40
  • 1
    Seethis answer.CommentedAug 20, 2016 at 17:17
  • @Aacini that was the answer I was looking for. Since the linked question is different, I think it would be beneficial if you answered it here as well. Will you please do that so that I can mark it as answered?CommentedAug 20, 2016 at 17:48

1 Answer1

12

The difference is thatcall execute the other Batch filein the same context of the caller program, so they share the same environment variables and other status (likeecho ON/OFF or delayed expansion), whereascmd /C execute the other Batch file in an entirely separated context, so any change made in the called Batch file isnot reflected in the original file.

Just as a personal note, I used to nameinternal subroutine the Batch file invoked viacall, andexternal subroutine the one invoked viacmd /C (andoverlay the Batch file directly invoked withoutcall norcmd /C, thatinherits the behavior and context of the caller Batch file).

answeredAug 20, 2016 at 18:01
Aacini's user avatar
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.