- NSIS Discussion
- Need help running a batch file
Archive: Need help running a batch file
pgg1
4th January 2008 21:02 UTC
Need help running a batch file
I want to launch my Java app via a batch file using NSIS once the installer has finished.
I've tested the batch file from the command line and it works fine.
I've tried the following using NSIS:
..
...
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_TEXT "Launch Zang"
!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchZang"
!insertmacro MUI_PAGE_FINISH
...
...
...
Function LaunchZang
ReadEnvStr $0 COMSPEC
nsExec::Exec '$0 /c "$INSTDIR\client\startZang.bat"'
FunctionEnd
The problem is that the app launches but doesn't get any further than the splash screen it just hangs there.
I do not wish to see a command window and have therefore used nsExec.
Any ideas would be greatly appreciated.
Regards
Paul g
Afrow UK
5th January 2008 01:07 UTC
Make sure you have the correct working directory set first with SetOutPath.
Stu
pgg1
5th January 2008 16:46 UTC
Hi
Thanks for the reply, I can't test that until i'm back to work on Monday morning.
I'm not sure that is the problem though. On the MUI_FINISHPAGE I have four check boxes, one of those is to launch the app, the second to show a README doc and the other two are for shortcuts.
My Finish page looks like this:
!define MUI_PAGE_CUSTOMFUNCTION_PRE CreateControls
!define MUI_PAGE_CUSTOMFUNCTION_SHOW SetControlColours
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE DisplayQuickLaunchAndDesktopIcon
!define MUI_FINISHPAGE_SHOWREADME
!define MUI_FINISHPAGE_SHOWREADME_TEXT "Show release notes"
!define MUI_FINISHPAGE_SHOWREADME_FUNCTION ShowReleaseNotes
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_TEXT "Launch Zang"
!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchZang"
!insertmacro MUI_PAGE_FINISH
and the 2 functions that launches the app and dislays the README stuff.
Function LaunchZang
ReadEnvStr $0 COMSPEC
nsExec::Exec '$0 /c "$INSTDIR\client\startZang.bat"'
FunctionEnd
Function ShowReleaseNotes
ExecShell "open" "$INSTDIR\README.txt"
FunctionEnd
The function ShowReleaseNotes works, but LaunchZang does not as previously explained.
What I don't understand is why does one work and the other doesn't. If I was in an incorrect working directory as you suspect then surely both would fail.
Regards
Paul
Afrow UK
5th January 2008 20:27 UTC
If your app uses relative paths then the working directory would need to be set correctly. Running notepad does not have the same dependency, although in theory if you went to File>Open in notepad, you'd find that it would open in the working folder you had set when you ran notepad.
Stu
pgg1
5th January 2008 21:04 UTC
I'll give that a go on Monday.
Thanks Stu.
pgg1
7th January 2008 12:23 UTC
Hi
Setting SetOutPath has worked and the application now launches.
Function LaunchZang
SetOutPath "$INSTDIR\client" ;new line
ReadEnvStr $0 COMSPEC
nsExec::Exec '$0 /c "$INSTDIR\client\startZang.bat"'
FunctionEnd
However, the finish page of the installer does not go away it just turns completely white.
It seems like the installer for whatever reason cannot end.
Any ideas what may be causing this.
Regards
Paul
pgg1
7th January 2008 12:53 UTC
Exec doesn't work
Hi
As I'm having difficulties running a bat file I thought I would you the same line of code from the .bat file and use Exec instead.
Function LaunchZang
SetOutPath "$INSTDIR\client"
Exec '"..\jre_v6\bin\javaw.exe" -cp .\BrowserLauncher2-10rc4.jar;.\Connected.jar;.\flickrapi-1.0b4.jar;.\jdic.jar;.\jh.jar;.\jregex1.2_01.jar;.\JSON.jar;.\mail.jar com.kc.pm.PhoneManager -Xmx210m'
FunctionEnd
This works perfect on my development machine, however, when I come to install the .exe on a new laptop the application does not launch from the finish page. You can only launch it from the shorcuts (Desktop & quicklaunch).
Any ideas?
Regards
Paul
Afrow UK
7th January 2008 13:15 UTC
The path $INSTDIR\jre_v6\bin\javaw.exe is correct?
Stu
pgg1
7th January 2008 13:40 UTC
Absolutely, I know for sure because the javaw.exe is in the process list.
Afrow UK
7th January 2008 15:30 UTC
Try using ExecWait with the extra exit code parameter and see what the exit code is.
Stu
pgg1
7th January 2008 16:41 UTC
Returns 0
Just to clarify, the following function displays 0.
Function LaunchZang
SetOutPath "$INSTDIR\client"
ExecWait '"..\jre_v6\bin\javaw.exe" -cp .\BrowserLauncher2-10rc4.jar;.\Connected.jar;.\flickrapi-1.0b4.jar;.\jdic.jar;.\jh.jar;.\jregex1.2_01.jar;.\JSON.jar;.\mail.jar com.kc.pm.PhoneManager -Xmx210m' $0
MessageBox MB_OK "return value $0"
FunctionEnd
The app launches but the installer does not close. Even when you click the finish button on the installer nothing happens. I have to kill the app, after that I get the error value of 0, then I get the README notes appear, only then does the installer close.
The version of NSIS I am using is 3.34 (e.g. the latest)
Regards Paul
Afrow UK
7th January 2008 17:21 UTC
ExecWait as the instruction suggests executes the command and waits for it to finish. There's no reason why ExecWait would work but Exec wouldn't...
Stu
pgg1
7th January 2008 17:36 UTC
Well all I can tell you is that it works fine on my development machine Both Exec and ExecWait. However, if I take the .exe and do an install on a new machine (e.g. a laptop) then it fails on both accounts.
I don't know what I am going to do! It's the same script for both machines. Do you have any further suggestions?
Regards
Paul
Afrow UK
7th January 2008 17:39 UTC
Feel free to send me your script and I shall take a look.
My E-mail address is on my web page: http://www.afrowuk.co.uk
Edit: Or attach here of course.
Stu
pgg1
7th January 2008 18:06 UTC
Thanks.
Thanks for that, I have already mailed it.
Cheers
Paul
Afrow UK
7th January 2008 19:30 UTC
Ok looking at the script, the command line exceeds MAX_PATH. Not sure if that matters but try putting \\?\ in front of the executable path.
Stu
pgg1
8th January 2008 10:22 UTC
Thanks,
I may have found the problem. Our Java application has DLL dependencies. These DLLs are put onto the system path. On my development machine this path is always set. When I do a build these DLLs are incorporated into the installer and the system path is set accordingly. When the application is launched from the finish page it it not picking up the path to the DLLs that I've included in the system path.
Providing I do not launch from the finish page and the installer finishes naturally the Desktop icon and Quick launch icon work perfectly because they start in a new process and pickup the system path.
Can can I launch from the finish page and pickup the system path? This will solve this issue.
Regards
Paul
Afrow UK
8th January 2008 13:04 UTC
This topic might help:
http://forums.winamp.com/showthread.php?threadid=273924
Stu
pgg1
10th January 2008 23:48 UTC
Thanks,
Sorry for the late reply but I got rail roaded into something else at work.
Anyway, I have read the topic that you recommended. I have used Kichik's script which can be found here: http://nsis.sourceforge.net/Path_Manipulation
I've added the additional code as per the topic. However, what is KEY_QUERY_VALUE defined as? The compiler is moaning and just ignores that line.
Any ideas?
Regards
Paul