August 31, 200520 yr 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...
August 31, 200520 yr 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, 200520 yr by Yzöwl
August 31, 200520 yr just quickly Yzöwl - whats the difference between %comspec% and call? i.e. pro's and con'sJust wondering CheersN.
September 1, 200520 yr 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.
September 1, 200520 yr Author 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, 200520 yr by fly
September 1, 200520 yr 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.
September 1, 200520 yr 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.
September 7, 200520 yr Can CALL execute a certain defined LABEL of a batch only instead of the whole batch file?
September 7, 200520 yr Yes, CALL accepts LABELs as a target. Type CALL /? at a command prompt for more information.
September 7, 200520 yr 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
September 7, 200520 yr 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...........
September 7, 200520 yr 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...
September 7, 200520 yr 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
Create an account or sign in to comment