1.

Solve : Calling up another batch file?

Answer»

How do I created a batch file that calls up another batch file if I type a name in the first batch file?Quote from: henksey on January 12, 2010, 08:40:03 AM

How do I create a batch file that calls up another batch file if I type a name in the first batch file?


C:\batch>type twobatch.bat
Code: [Select]@echo off

call batch_1.bat
echo return to main after batch one
call batch_2.bat

echo return to main after batch two

pauseC:\batch>type batch_1.bat

Code: [Select]echo DATABASE backup
rem rman target user/pwd @<path_to_file_to_run> log <path_to_log_file>
exit /b
C:\batch>type batch_2.bat

Code: [Select]echo CommVault backup

REM qlogin -cs "server_name" -u "user" -p "pwd"

exit /bOUTput:

C:\batch> twobatch.bat
Database backup
return to main after batch one
CommVault backup
return to main after batch two
Press any key to continue . . .
C:\batch>I have a distinct feeling that's not what he meant by 'type', Bill...
Thanks Bill. I really appreciate your reply. is there a more simple way of creating this type of batch. I am very very NEW at this, and i'm not understanding all your commandsI was talking about typing in the echo screen that comes up a name of another batch file to call it up. Something that says; " Type in name, then click on any key" once I do that then another specfic batch would open.You want set /p for that
hello I mis-stated my 1st question. So i'll restate it; How do I created a batch file that calls up another batch file, by typing the name in the 2nd batch file and then clicking on a key to bring it up? Trout, could you give me an example?

Thanks@echo off
set /p batchname=Batch name:
call "%batchname%"

Quote from: henksey on January 12, 2010, 09:33:58 AM
Could you give me an example?


C:\batch>type st.bat
Code: [Select]@echo off
echo Enter name of batch file.
set /p x=

call %x%
echo return to main after batch one

echo Enter name of batch file.
set /p y=

call %y%

echo return to main after batch two

pause
Output:

C:\batch>st.bat
Enter name of batch file.
batch_1.bat
Database backup
return to main after batch one
Enter name of batch file.
batch_2.bat
CommVault backup
return to main after batch two
Press any key to continue . . .
C:\batch>Thanks S.T., I think this will workC:\batch>call /?
Calls one batch program from another.

CALL [drive:][path]filename [batch-parameters]

batch-parameters Specifies any command-line information required by the batch program.

_________________________________

Keep in mind that the subBatch must contain the exit /b command for control to return to the main Batch.
For example:

echo in CommVault backup

REM qlogin -cs "server_name" -u "user" -p "pwd"

exit /bQuote from: BillRichardson on January 12, 2010, 10:05:50 AM

Keep in mind that the subBatch must contain the exit /b command for control to return to the main Batch.


Not exactly. When a CALLED batch terminates naturally (i.e. reaches the last line of code), control is passed back to the CALLING batch, which proceeds to the line FOLLOWING the call command. There is no need for the last line to be exit /b. However the exit command with the /b switch is useful for situations where you need to exit before the end of the batch is reached. The /b switch prevents a complete exit from cmd.exe.




Quote from: Salmon Trout on January 12, 2010, 01:12:03 PM
Not exactly. When a called batch terminates naturally (i.e. reaches the last line of code), control is passed back to the calling batch, which proceeds to the line following the call command. There is no need for the last line to be exit /b. However the exit command with the /b switch is useful for situations where you need to exit before the end of the batch is reached. The /b switch prevents a complete exit from cmd.exe.





Yeah or use

GOTO EOF
commands
:EOF


Discussion

No Comment Found