Old 11th September 2011, 19:19   #1
fyaa
Junior Member
 
Join Date: Sep 2011
Posts: 6
Get return-statement of a executed batch.

Hello,

I'm relatively new to working with the NSIS Installer. Most features are easy to handle and I get a success, but there is one thing which I didn't get a solution for.. I've been trying since yesterday morning, so hopefully you can help me with it .

After installing files to the install-directory, I have to start a Batch-file with parameters to do some operations.
So I do either
code:

ExpandEnvStrings $0 %COMSPEC%
ExecWait '"$0" /C "$SOMEDIRECTORY\my.bat" "quotedparameter" parameter2 parameter3' $0
MessageBox MB_OK "Exit code $0"


or
code:

ExpandEnvStrings $0 %COMSPEC%
ExecDos::exec '"$0" /C "$SOMEDIRECTORY\my.bat" "quotedparameter" parameter2 parameter3' '' "$EXEDIR\stdout.txt"
Pop $0
MessageBox MB_OK "Exit code $0"



..but nothing works like I supposed.
With option 1 I get a 1 whatever I do on input.
With option 2 I get always a -.

When I start the batch exclusively, it returns either "OK" or "ERROR".
This "State" I have to return to my NSIS installer. Depending on it the Installer will throw an Error in a MessageBox or continue.

So, how am I supposed to do this?
fyaa is offline   Reply With Quote
Old 11th September 2011, 19:33   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,277
Batch file exit codes are problematic. Are you using exit %somenumber% in your batch file?

ExecWait uses the exit code for the comspec process (Internally cmd.exe will call ExitProcess() with some number and that is the number you get)

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 12th September 2011, 06:42   #3
T.Slappy
Major Dude
 
T.Slappy's Avatar
 
Join Date: Jan 2006
Location: Slovakia
Posts: 542
Send a message via ICQ to T.Slappy
Please post your .bat file - or at least the most important part of it - that one which returns OK or ERROR. Use pastebin for this purpose

Cool looking installers with custom design: www.graphical-installer.com
Design NSIS setup Pages easily: www.install-designer.com
Build NSIS installers in Visual Studio 2005-2019: www.visual-installer.com
or RAD Studio 2009, 2010, XE-10.3 Rio: www.rad-installer.com
T.Slappy is offline   Reply With Quote
Old 12th September 2011, 09:20   #4
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
You may be better off just translating the batch file into NSIS code.

Stu
Afrow UK is offline   Reply With Quote
Old 12th September 2011, 19:08   #5
fyaa
Junior Member
 
Join Date: Sep 2011
Posts: 6
Hello again,

thanks for your anwsers.
It would be easier if I could modify the batch-filem but it's a batch file from an oracle database, so I can't modify it.
As an input I give this batch an tcl-file so that I can put an output like "OK", "ERROR" or something else.

Maybe I can encapsulate this propriate batch-file with a custom one and throw some error level depending on the output of the .. batch-file.

Like:
code:

Call path/to/batch.bat tclskript.tcl input1 input2.. or write this output to a variable?..
if %variable% == "OK" (
Exit /B 1
) else (
Exit /B 0
)


.. or something like this.

But I'm neither experienced in batch-programming nor in NSIS-scripting/programming.
fyaa is offline   Reply With Quote
Old 15th September 2011, 09:58   #6
fyaa
Junior Member
 
Join Date: Sep 2011
Posts: 6
Well it works now:

Just use:

code:

FileOpen $0 "$TEMP\test.bat" w
FileWrite $0 "SET OUTPUT=$\n"
FileWrite $0 "FOR /F $\"tokens=*$\" %%R IN ('$\"PATH\TO\my.bat$\"') DO SET OUTPUT=%%R$\n"
FileWrite $0 "IF %OUTPUT%==OK ($\n"
FileWrite $0 " exit /B 1$\n"
FileWrite $0 ") ELSE ($\n"
FileWrite $0 " exit /B 0$\n"
FileWrite $0 ")$\n"
FileClose $0



With:
code:

ExpandEnvStrings $0 %COMSPEC%
ExecDos::exec /NOUNLOAD /ASYNC '"$0" /C "$TEMP\test.bat"'
Pop $0
ExecDos::wait $0
Pop $0


you have the errorcode in $0. So it's in this example either 1 oder 0 and you can react on it using ${if}.

fyaa is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Tags
batch, execdos, execwait, nsis

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