- NSIS Discussion
- How do i cal and exe to run?
Archive: How do i cal and exe to run?
logoguy
7th February 2003 21:22 UTC
How do i cal and exe to run?
I am trying to install a bat and some files to a temp directory and then run the bat and then after the bat has benn completed delete the temp files (i dont mind if they stay there but it would help if they could be deleted).
kichik
7th February 2003 21:34 UTC
I would go with nsExec. It will wait for the batch and prevent a DOS window from coming up. Depending on what function you call it will log the output to the install log, or push it to the stack.
For example:
GetTempFileName $0
File/oname=$0 mybatch.bat
nsExec
::execToLog $0
Delete$0
>
logoguy
7th February 2003 21:42 UTC
okay that was spanish to me. I dont understand i am not a coder (hardware guy) Can you simlify that for me. Ir could you show me the code/command i wouold type into a text file for a nsis script.
kichik
7th February 2003 21:48 UTC
I did exactly that... GetTempFileName etc.
logoguy
7th February 2003 21:50 UTC
I can see that but am i able to use that in the nsis file and if so how do i place it?
kichik
7th February 2003 21:52 UTC
A section.
For example:
Section "run my batch file"
># copy above code here
>SectionEnd
>
logoguy
7th February 2003 22:05 UTC
okay did that and here is the ouput from the compiled install
---------
Output folder: C:\temp
Extract: patch.exe
Extract: run.bat
Extract: simcity4-NA.RTP
Extract: Readme.txt
Extract: C:\DOCUME~1\CHRIS~1.CHR\LOCALS~1\Temp\nst34.tmp
Could not find symbol: execToLog
Completed
---------
And here is the script
---------
; example1.nsi
;
; This script is perhaps one of the simplest NSIs you can make. All of the
; optional settings are left to their default settings. The installer simply
; prompts the user asking them where to install, and drops a copy of makensisw.exe
; there.
;
; The name of the installer
Name "Simcity4 patch installer"
; The file to write
OutFile "patcher.exe"
; The default installation directory
InstallDir C:\temp
; The text to prompt the user to enter a directory
DirText "This will place the patch files on your computer. Choose a directory"
; The stuff to install
Section "ThisNameIsIgnoredSoWhyBother?"
; Set output path to the installation directory.
SetOutPath $INSTDIR
; Put file there
File patch.exe
File run.bat
File simcity4-NA.RTP
File Readme.txt
SectionEnd ; end the section
Section "running batch"
GetTempFileName $0
File /oname=$0 run.bat
nsExec::execToLog $0
SectionEnd
; eof
-------
What am i doing wrong?
kichik
7th February 2003 22:09 UTC
OK, you are probably using b0 and not the latest CVS version. There was a bug that caused NSIS to be syntax sensitive on function names so you'll need to replace nsExec::execToLog with nsExec::ExecToLog.
And please attach large scripts next time, it makes the forum easier to read.
logoguy
7th February 2003 22:16 UTC
okay it did not post ne errors but it did not give me a a log nor did it pop up run the bat file.
kichik
7th February 2003 22:23 UTC
I don't understand. What do you mean by "pop up run the bat file."? Did it not run the batch file or only didn't pop up something? It is not supposed to pop up anything, it is supposed to copy any output from the batch file to the installer log. If the batch file doesn't have any output it won't nothing in the log. Did the batch file do his job or not?
A possible problem might be that the batch file assumes a certain current directory. The current directory of the installer is the directory in which it started. In the next version (that will hopefully come out tomorrow) there will be an option to change the current directory.
For now, if this is indeed the problem, you dynamically write the batch file from NSIS using FileOpen, FileWrite and FileClose.
But first try to give the batch file a .bat extension. Use:
GetTempFileName $0
Delete$0
StrCpy$0 "$0.bat"
>File /oname=$0 mybatch.bat
nsExec
::ExecToLog $0
Delete$0
>
Instead of the code above.
logoguy
7th February 2003 22:26 UTC
okay the bat file is being extracted to the dorevtory with the rest of the files (in this i case i have it set to "c:\temp" i think it is not finding th bat to run how do i set the directory of the bat. I am thinking it has something to do with the "gettempfilename"
kichik
7th February 2003 22:33 UTC
Can you please attach the batch file? I just want to make sure it is really needed to set the current directory.
logoguy
7th February 2003 22:35 UTC
umm it is one line, it is a command line app that has to run to open and use this other file that patches simcity4. and what i need to do is just run the bat file in the directory that all the files were extracted to.
kichik
7th February 2003 22:39 UTC
OK, then here is what you should use:
GetTempFileName $0
Delete$0
StrCpy$0 "$0.bat"
>FileOpen $1 $0 "w"
>FileWrite $1 "@echo off$\r$\n"
>StrCpy $2 $TEMP 2
FileWrite$1 "$2$\r$\n"
>FileWrite $1 "cd $TEMP$\r$\n"
>FileWrite $1 "simcity4patcher.exe$\r$\n"
>FileClose $1
nsExec
::ExecToLog $0
Delete$0
>
Replace simcity4patcher.exe with the right file name and you're set.
This piece of code create a new batch file that CDs to the $TEMP directory and launches the file from there. This will make sure it runs from the right current directory.
logoguy
7th February 2003 22:43 UTC
I am running an exe that has to ahve commands all i need is to launch a file that is extracted. I think ur going a little ober board.
kichik
7th February 2003 22:48 UTC
OK, you can always try to just extract the file, and use ExecWait on it. Earlier you said it was looking for files in his current directory, this way he won't find them. Trying never hurts though :P
Try:
SetOutPath $TEMPSimCityPatcher
File patcher
.exe
File otherfiles.dat
>#... more files
>ExecWait $TEMPpatcher.exe
RMDir/R $TEMPSimCityPatcher
>
If it says it can't find the files you'll have to do it with the code above.
logoguy
7th February 2003 22:53 UTC
Isnt there just a snipet that lets me launch a file from a specific directory (or in this case the one the files were installed to)
kichik
7th February 2003 22:57 UTC
Until tomorrow's version that's the code above. Didn't ExecWait work?
logoguy
7th February 2003 22:59 UTC
okay, got it with the execwait command now how do i log what happend in the commmand promt.
kichik
7th February 2003 23:02 UTC
To get the output into the log use nsExec::ExecToLog instead of ExecWait.
logoguy
7th February 2003 23:20 UTC
-------
Output folder: C:\temp
Extract: patch.exe
Extract: run.bat
Extract: simcity4-NA.RTP
Extract: Readme.txt
'run.bat' is not recognized as an internal or external command,
operable program or batch file.
Completed
--------
that is what it gave me when i used the "nsExec::ExecToLog"
kichik
7th February 2003 23:22 UTC
Use nsExec::ExecToLog on the exe too, not the batch file.
logoguy
7th February 2003 23:24 UTC
I am not trying to launch the exe the bat file does that there is not need to launch the exe it will just flach the program and what is used for and exit (it is a command line prog)
kichik
7th February 2003 23:29 UTC
Did ExecWait work with the batch file or the exe?
Why don't you want to run the exe? You said that the batch file only calls the exe anyway, so why not let nsExec do it?
It will all be a lot easier if you ZIP the batch file and the script and attach them here.
logoguy
7th February 2003 23:33 UTC
the batch it worked great with the batch
kichik
7th February 2003 23:35 UTC
Are you sure you have added $TEMP to the batch name? Because according to the error it searches for just run.bat and not $TEMP\run.bat.
logoguy
7th February 2003 23:37 UTC
i mean the ExecWait worked great witht he patch.
logoguy
7th February 2003 23:38 UTC
I decided not to put the bat file in a temp dorectory. I decide to just run it from the directory i extracted it too.
kichik
7th February 2003 23:39 UTC
And did you add $TEMP?
Can you please attach the batch file?
logoguy
7th February 2003 23:43 UTC
The script calls a prompt that runs the exe and a command atached. Cuz the exe cant be run with out the command to do what it has to do with this other file. I am not just calling an exe from the command promt it is a comand line tool that cant be run with out the being in a command prompt or a bat. I no this is all confusing to you i am sorry this seems so vauge.
logoguy
7th February 2003 23:52 UTC
This is the bat (it is a txt cuz it wont let me upload a file with the bat extension) it is one line.
kichik
8th February 2003 00:05 UTC
Good, now that we have the batch file I can tell you you don't need it. Just use:
nsExec::ExecToLog '"$TEMP\patch.exe" "$TEMP\simcity4-NA.RTP"'
NSIS can pass on command line arguments, you don't need no batch file for that. The above line should work.
logoguy
8th February 2003 00:42 UTC
It is working thank you so much
logoguy
8th February 2003 00:48 UTC
how do i launch a readme?
kichik
8th February 2003 12:26 UTC
Use ExecShell. For example:
ExecShell open "$INSTDIR\readme.html"
If you are using the Modern UI read its readme there is a better way.