I am trying to run a few simple batch commands in one batch.
For that matter each command is a batch command as follows:

 rails generate scaffold illness name:string
 rails generate scaffold ingredient name:string origin_id:integer

Now, instead of running all 30 commands, my batch file runs the first only and returns to the prompt line. So I have to run it manually.


You have to place the word call in front of the batch file...

@echo off
call rails generate scaffold illness name:string
call ralis generate scaffold ingredient name:string origin_id:integer

This assumes "rails" is really rails.bat.

  • 1
    Correct, or rails.cmd. It's annoying when you have to run a command and don't realize that it's a batch file, that happened to me just this morning. – Mark Allen Apr 27 '12 at 20:11
  • Thanks. is that the rule? inside batch exe are written as is and batch/cmd should be written with call prefix? – Bick Apr 27 '12 at 21:48

While the previous answer by jftuga is correct, the more complete answer is as follows:

@echo off
call rails generate scaffold illness name:string
call ralis generate scaffold ingredient name:string origin_id:integer

You have to place a call in front of each line in the batch file that is an external command triggering a new process if you want the script to continue after each call. So internal commands like DIR and COPY do not require a call. But running a new command prompt or even another batch file, control is handed off completely to that program, unless the word CALL is at the front of the line. Actually, the new command prompt will hand control back to the batch file once you Exit it.

Some programs will pause while they run, but return to the next line of the batch file after they complete. In the following batch file, the script will pause the same after each calling of Notepad and begin after Notepad has exited (both times). So they are effectively the same.

call notepad.exe
echo    It came back.

But when calling another batch file, complete control is passed to the new process unless there is a call in front. So in the following code, the first calling of a bat file will return when completed, but the second will never return, so the last echo line will never run. call firstBatch.bat SecondBatch.bat echo You will never see this line

I'm not sure how the rails command works, but it seems to be like a batch session. Perhaps it was a batch file. The first two calls to cmd will not return until you type exit in that instance, returning you to the earlier shell. The call is irrelevant. But the third uses the /c switch, which says to execute the command and return automatically. If you want to keep the new cmd session active after you send it a command, you use the /K switch. For more help on this: cmd /?

call cmd 
cmd /c dir
echo   You will see this after typing Exit twice to leave two new instances of cmd. The third instance returned automatically.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.