Jump to content

Weird - batch file won't continue after for loop


Recommended Posts

OK, I've had a couple of very late working nights, so I must be missing something painfully obvious here ... In my install script, I have the following chunk at the end ...

for /D %%i in (*) do (
%%i\installit.cmd %%~ni %DIR%%%i %KEY%
if exist "%DIR%%%i\finishup.cmd" REG ADD %KEY%\%%~ni /V 99 /D "%DIR%%%i\finishup.cmd %DIR%%%i"
if exist "%DIR%%%i\Application.html" copy /y "%DIR%%%i\Application.html" "%systemroot%\Config\%%i.html"
)

echo "OK - all done"
pause

%DIR% and %KEY% are both set higher up. The problem is that it never reaches the "OK - All done" echo statement. I see the last copy command just fine, and then the batchfile just ends. It doesn't do the expected Pause to hit any key, just returns to the prompt.

I know it's going to be a forehead slapper, but I don't see it just now through my blurred vision ...

D.

Link to comment
Share on other sites


for a in b do (

either -1 or + 1 or >< something in the last loop is causing it to hang. you could be trying to run past the array. perhaps not starting at 0 in array. instead the for loop is starting at one in arrary and when it attempts to read last part of array its not there because you didn't start at 0.

it could be last %dir% that you have set ealier is feeding a directory name that is to long in amount of characters or directory name is long name format and not 8.3 format.

Link to comment
Share on other sites

for /D %%i in (*) do (
%%i\installit.cmd %%~ni %DIR%%%i %KEY%
<snip>

Lets take the above:

If

*
=
F:\Software

and contains three subfolders named

Program1, Program2, Program3

i.e.

F:\Software\Program1, F:\Software\Program2, F:\Software\Program3

then

for each directory in F:\Software do (

Program1\installit.cmd Program1 %DIR%Program1 %KEY%

Program2\installit.cmd Program2 %DIR%Program2 %KEY%

Program3\installit.cmd Program3 %DIR%Program3 %KEY%

I'm guessing this is not what you want, so please explain your requirements!

Link to comment
Share on other sites

well that little snippet seems to work as expected if I run it on my machine. Try putting a pause statement inside of the loop and immediatley following for testing purposes as see if that gives a better clue as to what is going on.

Link to comment
Share on other sites

Try this vbs script

Save As CheckAndCopy.VBS

Const OverWriteExiting = True

this a varible that cannot be change threw the script, this over write the existing

file in the target location

Dim Var1, Var2

Varible1 = "YOUR_WHAT_EVER_HERE"

Varible2 = "YOUR_WHAT_EVER_HERE"

This is like the set in cmd promt.You are declairing the varibles for the script here.

These can be any name you want. They can be almost any thing you want.

Set Fso = CreateObject("Scripting.FileSystemObject")

Set Act = CreateObject("Wscript.Shell")

These are object that the script uses, they act like cmd promt various cmds

eg copy, delete etc

Note : For Every If there has to be a End If

If Fso.FolderExists("YOUR_WHAT_EVER_HERE") Then

This checks for the file or folder exists

this is where the script run it cmd if true

Else

Act.Popup "Error Missing File Or Folder", 7,"Error Missing", 0 + 32

This is what the script does if it false

Act.Popup "Completed The Copy Of" & vbcrlf & "YOUR_WHAT_EVER_HERE", 7,"Completed Copy", 0 + 32

This is a timed messagebox made with the Act object

Fso.CopyFile ("YOUR_WHAT_EVER_HERE") , ("YOUR_WHAT_EVER_HERE") , OverwriteExisting

Fso.CopyFolder ("YOUR_WHAT_EVER_HERE") , ("YOUR_WHAT_EVER_HERE"), OverwriteExisting

The Copy Cmd for The Script

Const OverWriteExiting = True

Dim Var1, Var2, Act, Fso

Var1 = "YOUR_WHAT_EVER_HERE"

Var2 = "YOUR_WHAT_EVER_HERE"

Set Fso = CreateObject("Scripting.FileSystemObject")

Set Act = CreateObject("Wscript.Shell")

'''''''''''''''''''COPY A FILE

If Fso.FileExists("YOUR_WHAT_EVER_HERE") Then

'''''''''''''''''''''''''''''''START LOCATION '''''''''''''''''END LOCATION

Fso.CopyFile ("YOUR_WHAT_EVER_HERE") , ("YOUR_WHAT_EVER_HERE") , OverwriteExisting

Act.Popup "Completed The Copy Of" & vbcrlf & "YOUR_WHAT_EVER_HERE", 7,"Completed Copy", 0 + 32

Else

Act.Popup "Error Missing File Or Folder", 7,"Error Missing", 0 + 32

End If

'''''''''''''''''''COPY A FOLDER

If Fso.FolderExists("YOUR_WHAT_EVER_HERE") Then

'''''''''''''''''''''''''''''''START LOCATION '''''''''''''''''END LOCATION

Fso.CopyFolder ("YOUR_WHAT_EVER_HERE") , ("YOUR_WHAT_EVER_HERE"), OverwriteExisting

Act.Popup "Completed The Copy Of" & vbcrlf & "YOUR_WHAT_EVER_HERE", 7,"Completed Copy", 0 + 32

Else

Act.Popup "Error Missing File Or Folder", 7,"Error Missing", 0 + 32

End If

Link to comment
Share on other sites

  • 2 weeks later...
for /D %%i in (*) do (
%%i\installit.cmd %%~ni %DIR%%%i %KEY%
<snip>

Lets take the above:

If

*
=
F:\Software

and contains three subfolders named

Program1, Program2, Program3

i.e.

F:\Software\Program1, F:\Software\Program2, F:\Software\Program3

then

for each directory in F:\Software do (

Program1\installit.cmd Program1 %DIR%Program1 %KEY%

Program2\installit.cmd Program2 %DIR%Program2 %KEY%

Program3\installit.cmd Program3 %DIR%Program3 %KEY%

I'm guessing this is not what you want, so please explain your requirements!

That's exactly what I want :)

Each directory has a standard installit.cmd that takes 3 parameters. The directories are numbered, as in 205.Program1, 210.Program2, 215.Program3 and so on. That lets me reorder the installation just by renumbering the directories. For example, for 210.FolderShare, installit.cmd contains :

@echo off

set NUM=%1
set DIR=%2
set KEY=%3

REG ADD %KEY%\%NUM% /VE /D "FolderShare v2.5.10" /f
REG ADD %KEY%\%NUM% /V 1 /D "%DIR%\FolderShareSetup-2.5.10.msi ALLUSERS=2 /qb-" /f

%DIR% is set further up in the batchfile to the Apps dir on the CD, which results in two keys being added to RunOnceEx :

....\RunOnceEx\210   -> FolderShare v2.5.10
....\RunOnceEx\210\1 -> d:\apps\FolderShareSetup-2.5.10.msi ALLUSERS=2 /qb-

If there was a finishup.cmd there, it would have looked like this :

....\RunOnceEx\210	 -> FolderShare v2.5.10
....\RunOnceEx\210\1 -> d:\apps\210.FolderShare\FolderShareSetup-2.5.10.msi ALLUSERS=2 /qb-
....\RunOnceEx\210\99 -> d:\apps\210.FolderShare\finishup.cmd

Everything works as expected, except for the final statements after the loop. I actually do a reg export there to check things out, but that never got executed, which led me to check more, which led to putting in the pause etc, which never gets hit.

Hrm ...

D.

Link to comment
Share on other sites

I must have been sleeping the last time I posted.

Add CALL to the installit.cmd line. (see below) That way it calls the cmd file and returns, otherwise it closes the one and continues on in installit.cmd until it finishes and it's done.

for /D %%i in (*) do (
CALL %%i\installit.cmd %%~ni %DIR%%%i %KEY%
if exist "%DIR%%%i\finishup.cmd" REG ADD %KEY%\%%~ni /V 99 /D "%DIR%%%i\finishup.cmd %DIR%%%i"
if exist "%DIR%%%i\Application.html" copy /y "%DIR%%%i\Application.html" "%systemroot%\Config\%%i.html"
)

echo "OK - all done"
pause

Edited by IcemanND
Link to comment
Share on other sites

The call command was what I was trying to explain in my cryptic response previously, I quoted only that line of the batch file and spelled out what it did.

However the response was:

That's exactly what I want :)
Without the call, control would not be passed back to the invoking script, after running any installit.cmd.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...