Old 13th January 2011, 10:06   #1
t0rb3n
Junior Member
 
Join Date: Mar 2009
Posts: 4
Exec in loop

Hi,

I'm trying to wrap a suit of installers. Since there may be many changes in the suit, it needs to be customizable by non-programmers.
Thus, my plan is to read a list of file names from a file and execute them, but only the last one gets executed. I tried Exec and nsExec::Exec, same result.

Here is the relevant part of the script:

code:

Section Main
FileOpen $0 "installers.lst" r
FileRead $0 $1
IfErrors end_loop
loop:
nsExec::Exec '"$1"'
Pop $2
MessageBox MB_OK "$1 returned $2"
ClearErrors
FileRead $0 $1
IfErrors 0 loop
end_loop:
FileClose $0
SectionEnd



The message box pops up for every item and shows return code "error", only the last item in the file is actually executed.
Am I doing it wrong? Or is this even intended behavior?

Thanks in advance!


PS: The installer.lst looks like this:
code:

externals.exe
test.bat
server\apache-tomcat-5.5.27.exe
util\Firefox Setup 3.6.exe

t0rb3n is offline   Reply With Quote
Old 13th January 2011, 11:39   #2
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
code:
!include TextFunc.nsh
...
ClearErrors
FileOpen $0 "installers.lst" r
${DoUntil} ${Errors}
FileRead $0 $1
${TrimNewLines} $1 $1
${If} ${FileExists} $EXEDIR\$1
nsExec::Exec `"$EXEDIR\$1"`
Pop $1
${EndIf}
${Loop}
FileClose $0

Firstly FileRead reads the newline characters so you must trim them. Secondly I would always use a full path.

Stu
Afrow UK is offline   Reply With Quote
Old 13th January 2011, 12:46   #3
t0rb3n
Junior Member
 
Join Date: Mar 2009
Posts: 4
Works perfectly, thank you so much!

PS: I hate newlines... : )
t0rb3n is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump