?
Solved

Complex DOs in a batch file

Posted on 2005-03-18
7
Medium Priority
?
252 Views
Last Modified: 2010-04-14
FOR /F "usebackq delims==" %%i IN (`type regions.txt`) DO @echo %%i

Hello.

I use the above example in a batch file to get one region at a time. My problem is that what I need to do for each region is quite complex, more than one line. One option would be to put all in another batch file, and use

FOR /F "usebackq delims==" %%i IN (`type regions.txt`) DO CALL otherstuff.bat %%i

but I would prefer to keep all in one batch file. Is this possible?

Thanks,
Joe
0
Comment
Question by:joeslomp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 96

Expert Comment

by:Lee W, MVP
ID: 13573072
I think I need more info to help you.  Can you provide 2 or 3 sample lines from the text file and details about what you do with them?  Yes, EVERYTHING should be possibly from one batch file.

One other note:  You don't have to type the text file.  You can simply reference it.  For example:

FOR /F "delims==" %%i IN (regions.txt) DO @echo %%i

0
 

Author Comment

by:joeslomp
ID: 13573188
Thanks, leew.

The file only contains region names (one word for each region). In fact I would like to not even use a file, and use the region name strings in my FOR command.

My DO actions are a sequence of other calls to many (20) other batch files, each batch file does something different with the region name.
0
 
LVL 96

Expert Comment

by:Lee W, MVP
ID: 13573217
Post a couple.  let me work out how a couple would work with things.
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 

Author Comment

by:joeslomp
ID: 13573256
For example

::joesbatchfile
set scriptsDir=%~dp0
REM this is a simple echo, but I would like to START all programs below for all regions
REM in the FOR loop
FOR /F "delims==" %%i IN (regions.txt) DO @echo %%i
REM
REM programs I need to start for each region
START "program 1" /W %scriptsDir%build01.bat
START "program 2" /W %scriptsDir%build02.bat
..
.. lots more
0
 
LVL 96

Accepted Solution

by:
Lee W, MVP earned 200 total points
ID: 13573327
I'm sorry, it's VERY late for me... maybe this will make more sense to me after I sleep....

Right now all I see is you echoing the region.  This makes no sense to me (right now).

the way I work, it would really help if you could post a couple of sample lines from REGIONS.TXT

As I think about it, if the REGIONS.TXT only contains one word for each region, then you don't need the delims parameter.  This should work:

FOR /F "tokens=*" %%i IN (regions.txt) DO @echo %%i

(Sorry, I know this isn't the question, but I like to see things optimized where I can...

Maybe you mean this?

FOR /F "tokens=*" %%i IN (regions.txt) DO (
   START "program 1" /W %scriptsDir%build01.bat
   START "program 2" /W %scriptsDir%build02.bat
)
0
 

Author Comment

by:joeslomp
ID: 13573345
Yes! That simple, once you know it! Thanks a bunch, and have a good night!
0
 

Author Comment

by:joeslomp
ID: 13573380
For completeness:

FOR /F "tokens=*" %%i IN (regions.txt) DO (
   START "program 1" /W build01.bat %%i
   START "program 2" /W build02.bat %%i
)

Of course, buil0n.bat need an exit line, to return control to the master batch.

Cheers,
Joe
0

Featured Post

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Check out the latest tech news, community articles, and expert highlights in August's newsletter.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question