Archive: Parameter /? and print out the description


Parameter /? and print out the description
Hi,

my installer supports startup parameters. If someone execute my installer with "/?" then the user should get a parameter description. How can I printout some text if someone execute my installer with the parameter "/?".

Best regards

Rainer


You can do it using these two functions:
http://nsis.sourceforge.net/wiki/Get...ine_parameters
http://nsis.sourceforge.net/StrStr


Name cmdlinehelp
Outfile "cmdlinehelp.exe"

Section ""
SectionEnd

Function .onInit
Call GetParameters
Pop $0
Push $0
Push "/?"
Call StrStr
Pop $1
StrCmp $1 "" done 0
MessageBox MB_OK "Available parameters are:$\r$\n/a does this$\r$\n/b does that"
done:
FunctionEnd

Function GetParameters
; GetParameters
; input, none
; output, top of stack (replaces, with e.g. whatever)
; modifies no other variables.

Push $R0
Push $R1
Push $R2
Push $R3

StrCpy $R2 1
StrLen $R3 $CMDLINE

;Check for quote or space
StrCpy $R0 $CMDLINE $R2
StrCmp $R0 '"' 0 +3
StrCpy $R1 '"'
Goto loop
StrCpy $R1 " "

loop:
IntOp $R2 $R2 + 1
StrCpy $R0 $CMDLINE 1 $R2
StrCmp $R0 $R1 get
StrCmp $R2 $R3 get
Goto loop

get:
IntOp $R2 $R2 + 1
StrCpy $R0 $CMDLINE 1 $R2
StrCmp $R0 " " get
StrCpy $R0 $CMDLINE "" $R2

Pop $R3
Pop $R2
Pop $R1
Exch $R0

FunctionEnd

Function StrStr
/*After this point:
------------------------------------------
$R0 = SubString (input)
$R1 = String (input)
$R2 = SubStringLen (temp)
$R3 = StrLen (temp)
$R4 = StartCharPos (temp)
$R5 = TempStr (temp)*/

;Get input from user
Exch $R0
Exch
Exch $R1
Push $R2
Push $R3
Push $R4
Push $R5

;Get "String" and "SubString" length
StrLen $R2 $R0
StrLen $R3 $R1
;Start "StartCharPos" counter
StrCpy $R4 0

;Loop until "SubString" is found or "String" reaches its end
loop:
;Remove everything before and after the searched part ("TempStr")
StrCpy $R5 $R1 $R2 $R4

;Compare "TempStr" with "SubString"
StrCmp $R5 $R0 done
;If not "SubString", this could be "String"'s end
IntCmp $R4 $R3 done 0 done
;If not, continue the loop
IntOp $R4 $R4 + 1
Goto loop
done:

/*After this point:
------------------------------------------
$R0 = ResultVar (output)*/

;Remove part before "SubString" on "String" (if there has one)
StrCpy $R0 $R1 `` $R4

;Return output to user
Pop $R5
Pop $R4
Pop $R3
Pop $R2
Pop $R1
Exch $R0
FunctionEnd

Hi,

i know this. I want to get the output in the dos box. So the user starts the dos box and enters "mysetup.exe /?" and now he should get the description in the dos box and not in a windows message dialog. Howto do this?

Regards

Rainer


Far as I know, that isn't possible in NSIS not even with a plug-in.


Couple ideas:
I'm assuming that your app mysetup.exe is a command-line tool of some type? if so, you might be able to dump the result to a text file and then use a DOS 'TYPE' command to display the results to a window.

However, if mysetup.exe is intended to be a windows app, then I'm not sure that a DOS box is what you'd want. For that, a scrollable text box might work better--perhaps even a license screen from an installer page.

If you wanted to run the command from Windows (say using a 'run' command), you could use this:

cmd /k type c:\path_to\tempfile.dat

the '/k' tells the command interpreter to keep the window open. Use '/c' instead to close the window. (Or, if you make a batch file to run the command, you could add a 'pause' command at the end to give the 'press any key to continue' option, which could then close the window then the user was done reading the info.)

Speed78, did you find a soluce? I try to do the same thing, and Comperio soluce open a new dos box...


Something like:

Name "Output"
OutFile "Output.exe"

Section
StrCpy $R0 "This example work$\nonly on Windows XP and higher$\n"
StrLen $R1 $R0

System::Call "kernel32::AttachConsole(i -1)i .r0"
StrCmp $0 0 end
System::Call "kernel32::GetStdHandle(i -11)i .r0"
System::Call "*(i 0)i .r1"
System::Call "kernel32::WriteConsole(i r0, t R0, i R1, i r1, i 0)"
System::Free $1
System::Call "kernel32::FreeConsole()"

end:
SectionEnd

Originally posted by xilay
Speed78, did you find a soluce? I try to do the same thing, and Comperio soluce open a new dos box...
Hi,

no my only solution is to create a seperate application which do this for me. I unpack it in the temp folder and execute ist with the exec plugin.

Regards

Rainer

no, that should be possible with NSIS.

i just think you'll need some plugin, or advanced api calls.

you can read command line parameters in .onInit, output the info and then immediatly quit.
thats no problem, so the GUI will never be loaded.

the problem is to output the information to a console window.