[windows2000] Re: Batch File Question

  • From: "Sullivan, Glenn" <GSullivan@xxxxxxxxxxxxxx>
  • To: "'windows2000@xxxxxxxxxxxxx'" <windows2000@xxxxxxxxxxxxx>
  • Date: Mon, 22 Sep 2003 13:13:36 -0400

The problem is really in the execution of the FOR loop...

A for /F loop is designed to iterate through out, and react to, each LINE,
maybe by breaking it into sub parts.

You are trying to make it react to each segment in the SAME line.  Not what
it was designed for.

You need your "array" to be on separate lines somehow.  For example:

<------------Start-------------->
@Echo Off
echo "C:\Program Files\proga.exe" >c:\ProgToRun.txt
echo "C:\Program Files\progb.exe" >>c:\ProgToRun.txt
echo "C:\Program Files\progc.exe" >>c:\ProgToRun.txt

set Sleep="C:\Program Files\sleep.exe"

:: Run each program with a 30 second delay in between
for /f "eol=/ delims=" %%i in (c:\ProgToRun.txt) do (
   :: echo %%i
   %Sleep% 30
   START "" %%i
)
<----------End---------------->

This builds a CR/LF delimited array, instead of a semi-colon delimited
array.  It is much easier to handle.

Notice that the "array" gets built on the local user's hard drive... this is
to prevent someone else from overwriting one user's "list" with another's.

And, you would always have a local record of what ran last time that user
logged in...  Until they log in again, it will not get wiped out.

Sound good?

Glenn Sullivan, MCSE+I  MCDBA
David Clark Company Inc. 

-----Original Message-----
From: Mike Dillinger [mailto:miked@xxxxxxxxxxxxxx]
Sent: Monday, September 22, 2003 12:31 PM
To: Braebaum, Neil
Subject: [windows2000] Re: Batch File Question


--- Original Message
From: Braebaum, Neil <windows2000@xxxxxxxxxxxxx>
Date: Monday September 22 2003 02:00AM PT

BN> In this scenario, though, why build a loop - you are not truly building
BN> an array, anyways, as cmd / bat files don't truly support the concept.

BN> If you are always merely going to hard-code the list, why bother looping
BN> it?

BN> You will just end up with a script that appears needlessly complex for
BN> the task it does. By all means, learn scripting concepts by writing
BN> scripts, but I can't see the sense in making a script you are going to
BN> use in production, needlessly complex.

Hi Neil,

I guess it's all relative.  To us, it's easier to do the for loop, but I
suppose it's the software developers in us.

If no one knows how to help me, that's cool and we'll just end up doing
it the long way.

Thanks,
-MikeD



**********************************************************
To Unsubscribe, set digest or vacation
mode or view archives use the below link.

http://thethin.net/win2000list.cfm

**********************************************************
To Unsubscribe, set digest or vacation
mode or view archives use the below link.

http://thethin.net/win2000list.cfm

Other related posts: