Results 1 to 11 of 11

Thread: Multiple commands in batch file loop

  1. #1
    Join Date
    Nov 2005
    Posts
    38

    Multiple commands in batch file loop

    I am running windows Vista enterprises. I have a small question hope you guys can help me out with this. I just wanted to know is it possible to execute more than one command in a batch file for each iteration of a FOR loop? I mean i want to run multiple commands for each file of the set. Is there anyway doing the same ?

    Thanks for your helps.

  2. #2
    Join Date
    Sep 2004
    Posts
    57

    Re: Multiple commands in batch file loop

    Yes, it is possible. In order to do the same you can create a secondary batch file that processes each file and call it like this:

    for %f in (*.txt) do call process.bat %f

    =process.bat=
    @Echo Off
    Command1.exe %1
    Command2.exe %1
    etc...

    Let me know if you need anymore help with this.

  3. #3
    Join Date
    Jul 2004
    Posts
    146

    Re: Multiple commands in batch file loop

    That is correct to some extent Casher but better than that you should also include the PowerShell equivalent like this :

    gci *.txt | % {Command1.exe $_.FullName; Command2.exe $_.FullName}

  4. #4
    Join Date
    Sep 2004
    Posts
    119

    Re: Multiple commands in batch file loop

    I dont think you actually need to use a separate batchfile. Instead you can do that in the same batch by using ( and ) like this:

    For %%f in (*.txt) do (
    Command1 %1
    Command2 %1
    )

  5. #5
    Join Date
    Feb 2009
    Posts
    33

    Re: Multiple commands in batch file loop

    Hey even I was trying to find an answer for the same problem with commands in loop! Here i found some help with the batch files for loop!

    I hope this helps you guys too!

  6. #6
    Join Date
    Sep 2010
    Posts
    1

    Re: Multiple commands in batch file loop

    i need to test or avability of keyboard & mouse through batch file. Pl help

  7. #7
    Join Date
    Nov 2009
    Posts
    359

    Re: Multiple commands in batch file loop

    Why do you need to write a batch script to test your keyboard and mouse. It is really simple by interrogating the system you can esaily detect if your keyboard and mouse are enabled or disabled.

    Alternative you can use the PassMark KeyboardTest -
    It is a tool for advanced configuration for your keyboard. You may like to check that your keyboard keys and the LEDs (Num Lock, for example) work correctly. In addition, the application analyzes your typing and how you show your typing speed and sensitivity recommended depending on your habits.

  8. #8
    Join Date
    Nov 2010
    Posts
    2

    Re: Multiple commands in batch file loop

    hi guys i also have a problem. im trying to get my batch file to start over once it has finished.

    my batch files looks like the following...

    netsh wlan connect SKY03175 SKY03175
    ping 127.0.0.1 -n10 -w 1000
    ftp uploads.google.com
    :top
    GOTO top

    now the batch file itself works fine. but the goto command only executes once i type in bye. and then all i get is a continouos list appearing like so

    c:\GOTO top
    c:\GOTO top
    c:\GOTO top
    c:\GOTO top

    this doesnt stop until i manually stop it.
    so basically the loop is failing to work in the way i want it to. help will be much appreciated :)

  9. #9
    Join Date
    Apr 2011
    Posts
    1

    Re: Multiple commands in batch file loop

    mkay i registered on the forum just to help you out, try something like this
    :top
    netsh wlan connect SKY03175 SKY03175
    ping 127.0.0.1 -n10 -w 1000
    ftp uploads.google.com
    choice /c:yn /m "run again?"
    if errorlevel 2 goto top

  10. #10
    Join Date
    Aug 2011
    Posts
    542

    Re: Multiple commands in batch file loop

    I prefer to go with a Batch File Maker. There are certain tools that can help you to generate a automated script for a process. You can edit that script and find the right command. Tool called as Batch File Maker is much easier to create batch files and modify them as per your need. The command line tool offer you to generate files with .bat exenstion and you can simply run them via cmd or run box. As the location for them is set to system32 folder inside Windows.

  11. #11
    Join Date
    Aug 2011
    Posts
    397

    Re: Multiple commands in batch file loop

    I remember a tool called as ZIP Batch File Maker. I had used this tool on Vista and it worked simply well. What I do not find is many customization option tha we need. There are certain sample script on the web that you can download and use. Somehow the most irritating stuff is when you get that error in a ongoing process. Still there is not proper application that can help to generate a good batch file.

Similar Threads

  1. Multiple commands for a batch file in a for loop?
    By SANDESH49 in forum Software Development
    Replies: 4
    Last Post: 08-05-2012, 10:40 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, 11:49 AM
  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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •