Results 1 to 5 of 5

Thread: Multiple commands for a batch file in a for loop?

  1. #1
    Join Date
    Aug 2008
    Posts
    475

    Multiple commands for a batch file in a for loop?

    HI,

    Multiple commands for a batch file in a for loop?

    Is this possible to do?

    Regards,

  2. #2
    Join Date
    May 2008
    Posts
    44

    Re: Multiple commands for a batch file in a for loop?

    You need to code ONE command per line and checking errorlevel has to be coded as below, i.e.

    for /f "options" %%a in (fileset.txt) do (
    fc /b /c %source%\%%d
    if errorlevel 1 call error.bat)

    or use the conecting operator ||

    for /f "options" %%a in (fileset.txt) do (
    fc /b /c %source%\%%d || call error.bat)

    Anyway your FC command lacks the second file to be compared.

  3. #3
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Multiple commands for a batch file in a for loop?

    You could try using the ampserand...

    FOR something DO command1 & command2 & command3

    but I really don't like doing that in loops or IF statements. Instead, use parens.

    For something DO (
    command1
    command2
    command3
    )
    NOTE: the parens should be used in the exact syntax above - I'm fairly certain trying
    FOR something Do (something & something & something)
    won't work, nor will
    IF something (something & something & something) ELSE (something & something & Something)
    (Haven't tested either of the above, but paren use in batch files can be picky - they should always work if you do them the way I first demonstrated).

  4. #4
    Join Date
    Apr 2009
    Posts
    569

    Re: Multiple commands for a batch file in a for loop?

    It can be done by creating different kind of bat file and then calling them one by one. I had seen certain script which workfine in that way. What you need to do is creat a multiple bat file like1.bat, 2.bat, 3.bat, etc. Then create a another script and call them one by one and loop if you want to run that file back again. In this way you can add multiple files inside a single script. This works fine, check properly that you are not missed any code.

  5. #5
    Join Date
    Jun 2011
    Posts
    45

    Re: Multiple commands for a batch file in a for loop?

    I found a another way by which you can run multiple file from the run file. It is right that you need to bifurcate the script in different files. Then you can run that in the form task. For example schtasks /run /tun first task schtasks /run /tun second task, etc. Try this out and run them all once. I hope this script can help you to some extent. There are number of complications involved building up multi command loop script.

Similar Threads

  1. Multiple commands in batch file loop
    By Toshaan in forum Vista Help
    Replies: 10
    Last Post: 08-05-2012, 10:39 AM
  2. How to execute commands of batch file at timed intervals
    By Camryn in forum Software Development
    Replies: 5
    Last Post: 27-03-2010, 08:47 PM
  3. Batch File Commands
    By Pratap Gad in forum Operating Systems
    Replies: 3
    Last Post: 30-07-2009, 08:07 PM
  4. Batch Commands To Read and Delete Lines from txt-File
    By officer07 in forum Windows Server Help
    Replies: 3
    Last Post: 04-03-2009, 12:49 PM
  5. How to create a script in a DOS batch file to do a loop?
    By Jon Osborn in forum Windows Server Help
    Replies: 2
    Last Post: 27-05-2008, 06:41 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,625,382.57569 seconds with 17 queries