Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have 3 batch files, lets call them batchA batchB and batchC. I double click batchA which later has a call batchB and call batchC in the script. I only see one CMD.exe process when it runs, and the Applications tab of task manager shows only the batchA. How does it work? Does it run as threads within a single process, or does it fork and create multiple processes (and I just didn't notice)? Windows XP 32 bit in this case, but I'll accept answers for Windows 7 64 as well.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

The CALL command executes a second batch file in the context of the first batch file. It's as if the first batch file contained the contents of the second batch file instead of the CALL command. There is only one cmd.exe process, and there is only a single thread (execution of the first batch file is suspended while the second is executing).

share|improve this answer
    
I tried it and you are correct. Do you know how this works behind the scenes? Is the content of the called script appended to the section of memory that the first script was using? –  user160910 Jul 12 '13 at 13:11
    
@GreggLeventhal I'm not sure what you're asking. The interpreter just opens the specified file and reads and executes the content. –  mgorven Jul 12 '13 at 16:58
    
@GreggLeventhal Here's the FreeDOS cmd.exe implementation of CALL‌​. –  mgorven Jul 12 '13 at 17:02
    
CMD.EXE actually rereads the BAT file every time a command is executed. You can see this yourself by creating a .BAT file that runs in a loop, executing the BAT file, and then editing it while it is running. As soon as you save the edits the (concurrently) executing BAT file starts executing the changes. –  user2460798 Jul 15 '13 at 15:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.