- NSIS Discussion
- Passing name of a batch file as a parameter
Archive: Passing name of a batch file as a parameter
cchian
23rd May 2002 23:03 UTC
Passing name of a batch file as a parameter
I must call my NSIS setup.exe file from within a batch file and I need to assign to a variable the name of the batch file that called setup.exe
Alternatively I could place the name of the file (or a parameter) after setup.exe (as in the sample batch file below) and somehow I would like to assign that file/parameter to a variable. I tried using the GetParameters sample listed in Functions.htm, but have not been able to figure it out.
Thanks
MyFile.bat
------------------------
Setup.exe TestMode
------------------------
sdbarker
24th May 2002 00:56 UTC
in your batchfile:
setup.exe /Dcaller=%0
and then you should have ${caller} defined as you batchfile name.
untested, but it should work.
-Scott
cchian
24th May 2002 03:30 UTC
Scott or anyone,
Can you provide some more details? I have not been able to figure it out yet.
Thanks
Smile2Me
24th May 2002 08:36 UTC
/D is only for the compiler, not for the installer.
Can't you do it without this batch file? Maybe the installer can take over the functions of the batchfile. Else, write a small txt file to $TEMP and let the installer read it. Or use the registry...
-Hendri.
kichik
24th May 2002 11:56 UTC
I agree with Hendri, everything that can be done with a batch can be done with NSIS. If you still want to do it with the batch file you sohuld call setup.exe like this:
setup.exe %0
And in NSIS:
Call GetParameters
Pop$1
MessageBox MB_OK$1
>
You will see that $1 now contains the paramters you sent to setup.exe which is the name of the batch file. If $1 does not contain the path to the batch file you can always add $EXEDIR to it.
cchian
24th May 2002 18:38 UTC
Thanks for the suggestions guys, I will try them soon. I am using NSIS to create a utility to perform certain things. This file needs to be called by third-party software and usually they specify it must be a batch file, that is why I am having the batch file call my NSIS file.
I want the NSIS file to look for some values in the calling batch file, that is why I need the utility to find out the name of the batch file. I don't want to create a different exe for each product so I want to be able to read the variables from an external file which in this case would be in the batch file itself (If I can read the values from the batch file, I only need to have two files instead of three).
Now I just need to figure out how to read a batch as if it was an ini file.
Carlos
cchian
29th May 2002 23:10 UTC
Hi,
Using the unmodified "GetParameters" code in Functions.htm and Kichik's suggestion, I am able to get the name and full path of the calling batch file. Is there a way to just get the name of the calling batch file without it's path?
Carlos
Smile2Me
30th May 2002 07:42 UTC
Modify the code of GetParent to not cut the first part but the last part from the full path. Eg.:
Function GetParentMod
Exch $0 ; old $0 is on top of stack
Push $1
Push $2
StrCpy $1 -1
loop:
StrCpy $2 $0 1 $1
StrCmp $2 "" exit
StrCmp $2 "\" exit
IntOp $1 $1 - 1
Goto loop
exit:
IntOp $1 $1 + 1 ;modified
StrCpy $0 $0 "" $1 ;modified
Pop $2
Pop $1
Exch $0 ; put $0 on top of stack, restore $0 to original value
FunctionEnd
-Hendri.
cchian
31st May 2002 01:17 UTC
Thanks Hendri, I tried the modified Function GetParentMod and it works great under Win95, but when tested under Win 2000, for some strange reason it adds a " at the end of the calling file name (ie: mybatch.bat").
Carlos
Smile2Me
31st May 2002 07:43 UTC
I don't see the reason why this would happen, but you can always check for this and delete the " if necessary:
; Put string
StrCpy $0 'C:\My docs\prob.exe"'
MessageBox MB_OK $0
; Perform check
StrCpy $1 $0 "" -1
StrCmp $1 '"' 0 Done
StrCpy $0 $0 -1
Done:
MessageBox MB_OK $0
-Hendri.
cchian
1st June 2002 06:19 UTC
Great! It now works properly under Win 2000. I still need to test it under a variety of systems. Many thanks to Hendri and those who provided suggestions.
Carlos
Smile2Me
1st June 2002 08:46 UTC
Thx Carlos.
-Hendri.