fly Posted August 31, 2005 Share Posted August 31, 2005 I know I've seen it here somewhere, but can't find it. Sadly, I suck at writing batch files, or I'd just do it myself.I'm hoping to use the batch file to install all my apps... Link to comment Share on other sites More sharing options...
Yzöwl Posted August 31, 2005 Share Posted August 31, 2005 (edited) Is this what you mean?for %%a in ("*.cmd") do %comspec% /c "%%~a"<Edit>You don't have to use '%comspec% /c', you may prefer to use 'call'</Edit> Edited August 31, 2005 by Yzöwl Link to comment Share on other sites More sharing options...
tarquel Posted August 31, 2005 Share Posted August 31, 2005 just quickly Yzöwl - whats the difference between %comspec% and call? i.e. pro's and con'sJust wondering CheersN. Link to comment Share on other sites More sharing options...
MHz Posted September 1, 2005 Share Posted September 1, 2005 I will help answer that query.Call is internal method to a execute a batch file. The batch file will pause, until the Call to the executed batch ends. The same instance of %ComSpec% does the operation for the entire loop.%Comspec% is executing cmd.exe externally. This means that %ComSpec% is started For each loop. This is by far the slowest and inefficient method. Link to comment Share on other sites More sharing options...
fly Posted September 1, 2005 Author Share Posted September 1, 2005 (edited) Is this what you mean?for %%a in ("*.cmd") do %comspec% /c "%%~a"<Edit>You don't have to use '%comspec% /c', you may prefer to use 'call'</Edit><{POST_SNAPBACK}>Will that execute all .cmds in the directory, and only once?EDIT: LOL, I guess I can't give this file name a .cmd, as it loops repeatedly then. What does the /c do? As it just errored out for me. Edited September 1, 2005 by fly Link to comment Share on other sites More sharing options...
MHz Posted September 1, 2005 Share Posted September 1, 2005 An example:Master.cmdfor %%a in ("Files\*.cmd") do Call "%%~a"The above will execute the *.cmd files in the files directory, next to the script. Create a folder called files and create a cmd script with below in it.Slave.cmd@echo offecho.echo everything is working okecho.pauseNow run the Master.cmd and you will see it execute the Slave.cmd. If you had other *.cmd scripts in files folder, then they would be executed also.If you type cmd /? in the command console. It will tell you what /c does.Carries out the command specified by string and then terminatesBut as I have stated. Call is the best command for this purpose. Link to comment Share on other sites More sharing options...
Yzöwl Posted September 1, 2005 Share Posted September 1, 2005 Try this as a test, replace the pushd line with the location of your filespushd C:\Documents and Settings\Administrator\Desktop\Batch Filesfor %%a in ("*.cmd") do echo/call %%~napause&popdWhen you've confirmed if and how the output works remove the echo/ and pause& and you're good to go. Link to comment Share on other sites More sharing options...
fly Posted September 1, 2005 Author Share Posted September 1, 2005 Thanks guys! Link to comment Share on other sites More sharing options...
MioKawaii Posted September 7, 2005 Share Posted September 7, 2005 Can CALL execute a certain defined LABEL of a batch only instead of the whole batch file? Link to comment Share on other sites More sharing options...
MHz Posted September 7, 2005 Share Posted September 7, 2005 Yes, CALL accepts LABELs as a target. Type CALL /? at a command prompt for more information. Link to comment Share on other sites More sharing options...
Yzöwl Posted September 7, 2005 Share Posted September 7, 2005 Yes, basically you use CALL MyBatch to call another batch file and CALL :MyLabel to do as you asked. The last command under your label should preferably say GOTO :EOF, to pass the command back to the next command after CALL :MyLabel.Example@ECHO OFFECHO. THIS IS MY FIRST ECHO COMMANDCALL :SECONDECHO. THIS IS MY THIRD ECHO COMMANDGOTO :ENDIT:SECONDECHO. THIS IS MY SECOND ECHO COMMANDGOTO :EOF:ENDITECHO. THIS IS THE END, GOODBYEPAUSEEXIT Link to comment Share on other sites More sharing options...
MioKawaii Posted September 7, 2005 Share Posted September 7, 2005 Yes, CALL accepts LABELs as a target. Type CALL /? at a command prompt for more information.<{POST_SNAPBACK}>Yes, basically you use CALL MyBatch to call another batch file and CALL :MyLabel to do as you asked. The last command under your label should preferably say GOTO :EOF, to pass the command back to the next command after CALL :MyLabel.Example@ECHO OFFECHO. THIS IS MY FIRST ECHO COMMANDCALL :SECONDECHO. THIS IS MY THIRD ECHO COMMANDGOTO :ENDIT:SECONDECHO. THIS IS MY SECOND ECHO COMMANDGOTO :EOF:ENDITECHO. THIS IS THE END, GOODBYEPAUSEEXIT<{POST_SNAPBACK}>Sorry, that wasn't in my mind. I asked the wrong question. The question should be put in this manner:I have a batch file with multiple LABELs, how do I execute certain LABEL from outside of the batch file? eg. command prompt, registry........... Link to comment Share on other sites More sharing options...
cyberloner Posted September 7, 2005 Share Posted September 7, 2005 command acommand b command call above in one batch file..and u wanna call a from outside?u think too much...remember u are under dos... and single task not multitask platform... Link to comment Share on other sites More sharing options...
jaclaz Posted September 7, 2005 Share Posted September 7, 2005 I have a batch file with multiple LABELs, how do I execute certain LABEL from outside of the batch file? eg. command prompt, registry...........You pass the label as a parameter:BATCH1.CMD:@ECHO OFFCALL BATCH2.CMD 1stLABELpauseCALL BATCH2.CMD 2ndLABEL:ENDBATCH2.CMD@ECHO OFF::Following line checks for the parameter passed when calling the file, if it is not ::passed by the calling (batch or command) it ends programsIF %1.==. GOTO :ENDGOTO %1:1stLABELECHO This is 1stLABELPAUSEGOTO :END:2ndLABELECHO This is 2ndLABELPAUSEGOTO :END:ENDECHO This is END of BATCH2.CMDPAUSEjaclaz Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now