- NSIS Discussion
- Need help with GetParameters function
Archive: Need help with GetParameters function
cchian
8th October 2002 23:06 UTC
Need help with GetParameters function
I currently have code that will give me the name of the batch file calling the NSIS executable (I must use a batch file for this application). The program that calls the batch file is another software that passes some data to our app by means of the batch and NSIS file combination.
Here is my current batch file code:
copy %1 mydata.dat
myapp.exe %0
As I mentioned above, I can already get the name of the batch file with the %0 parameter. What I would also like to do is to pass it the data with the %1 parameter so my batch file should just be something like:
myapp.exe %0 %1
The problem is I cannot figure out how to get %1 so I can copy it into a file/variable. How do I read the second parameter?
Joost Verburg
9th October 2002 07:36 UTC
Re: Need help with GetParameters function
Put quotes around the parameters, so you will know when the second one starts.
cchian
9th October 2002 21:04 UTC
I added quotes around the parameters so my batch file now looks like:
myapp.exe "%0" "%1"
I also added the following two things right before closing the GetParameters Function code:
* A message box to show me the values of $0, $1 and $2
( This is the code: MessageBox MB_OK "0=$0$\n1=$1$\n2=$2" )
* StrCpy $1 c:\mydata.dat
The values of $0, $1 and $2 come up blank and the data being transferred doesn't get copied into c:\mydata.dat
cchian
9th October 2002 21:07 UTC
I forgot to mention that I am using 1.98
Joost Verburg
9th October 2002 21:31 UTC
You need to write some code to separate these parameters. The StrCpy instruction does not write stuff to a file, it just copies a variable.
Can you post the other code?
kichik
9th October 2002 21:54 UTC
$0, $1 and $2 are not the equivalent of %0, %1 and %2... You have to call the GetParameters function, then Pop to get its result and parse it. If you used myapp.exe "%0" "%1" to call the installer the string popped will be "%0" "%1" (%0 and %1 of course replaced by their real values...). You will then have to seperate this string to two strings by searching for the quotes and using StrCpy starting position parameter and number of characters to copy parameter.
eccles
9th October 2002 22:20 UTC
Using the function GetNextParm, this should do the trick:
Push $CMDLINE
Call GetNextParm
Pop $0 ; name of installer
Call GetNextParm
Pop $1 ; first parameter
Call GetNextParm
Pop $2 ; second parameter
Pop $9 ; remaining parameters (not required - just keeping the stack tidy)
cchian
9th October 2002 22:24 UTC
Attached is my NSIS script and batch file zipped up.
I will try to figure out Kichik's suggestion of "You will then have to seperate this string to two strings by searching for the quotes and using StrCpy starting position parameter and number of characters to copy parameter."
Thank you
kichik
10th October 2002 12:00 UTC
Using GetNextParm will actually be easier :)
cchian
10th October 2002 18:02 UTC
Thanks for the help, but I am still having problems figuring out how to implement the "GetNextParm" function in my code. I added the "GetNextParm" function as posted by eccles and called it from the .OnInit function (after "Call GetParameters"), but now I am getting a stack fault error when the exe is executed. What am I doing wrong?
kichik
10th October 2002 20:56 UTC
You have an example of usage in the URL eccles gave you. You don't need to call GetParameters if you use GetNextParm...
tderouin
21st February 2003 18:31 UTC
GetNextParam should be using $R0..$R9 and not $0..$9. Using $9 around the start menu functionality in Modern UI wipes out the Start Menu folder.
kichik
21st February 2003 18:35 UTC
Where did you find GetNextParm? The links above are dead.
tderouin
21st February 2003 18:41 UTC
That's a good question, I think I found it in included example piece of code posted somewhere on this board, but I can't remember where.
Sunjammer
21st February 2003 21:47 UTC
I still have the backups of that clantpa site. Does anyone want me to fish out the stuff that those dead links used to refer to?
kichik
21st February 2003 21:50 UTC
I'll be happy to polish it if I'll get a copy of it ;)
Sunjammer
21st February 2003 22:26 UTC
clantpa.co.uk backup files
Here it is.
Also for anyone interested (you're pretty mad if you try this) I've made the backups accessible by ftp (ftp://nsis:nsis@sunjammer.serveftp.net). The reason I've done this is that I have very little time to go through them and yet there is potentially still useful information in there.
Sunjammer
21st February 2003 22:28 UTC
Hmm forgot the file :D
kichik
21st February 2003 23:09 UTC
It uses $9 in the example but in the function itself pushes and pops like needed. If you want to perform the check in the installer you can use this function, it's optimized for that task:
http://nsis.sourceforge.net/archive/....php?pageid=79