Archive: variable in dos


variable in dos
Hi,

Is there any way to make a viariable of NSIS also work in a dos command line. Here is an example of my issue.

____________________________________________________________

ShowInstDetails show
Name "xxxxxxxxxx"
OutFile "xxxxxxxxxx"
XPStyle on

;---- Initialen wegschrijven ----
!include "dialogs.nsh"
Function .onInit

# Params:
# 1) Title: "xxxxx"
# 2) Caption: none
# 3) InitText: (enter owner code)
# 4) Max: 3
# 5) Button1: default
# 6) Button2: default
# 7) Return: $0
${InputTextBox} "xxxxx" "Please, enter xxx " "" "2" "" "" 1

FunctionEnd

Section

# See if the user inputs something:
${if} $1 == "${NULL}"
DetailPrint "Operation was canceled!"
${else}
FileOpen $0 c:\temp.txt "a"
FileSeek $0 0 END
FileWrite $0 "$1"
FileClose $0
${endif}

SectionEnd

wath I want now is, run a command line where can use the variable $1. For example: alter.exe file.txt "xxx" "$1"
This means I search in the file.txt for the word "xxx" and i will replace is with the value of variable "$1"

Brgd


There are functions in the NSIS Wiki to replace text in a file:
http://nsis.sourceforge.net/wiki/Cat...tion_Functions

To run programs, use Exec, ExecWait or nsExec::Exec (which hides the window too).

-Stu


microsoft
Hi thx for the information but i don't get is done. Can you please explain me how to use the Replace function.


This function has many examples:
http://nsis.sourceforge.net/wiki/Mor...e_text_in_file

-Stu


microsoft
Hi Afro UK, still not clear for me. On the page you say I can find a few examples buth what do I need to do with the whole function AdvReplaceInFile. Do I need to copy it and make it an AdvReplaceInFile.nsh file. Please help me because I don't get it. Thx Tupsan


Just put the function in you script.

-Stu


Hi,

I've found out how it works. I have one small problem. When I compile the script i don't get errors only when I run the program I get an error. I've attachet the error. Here is my code. Can you help me.
____________________________________________________________

;---- Algemene Configuratie ----

Name "Config.nt"
OutFile "config_nt.exe"
SilentInstall "Normal"
DetailsButtonText Details

;---- Algemene Configuratie ----

Section

Push 40 ;text to replace
Push 120 ;replace with
Push $SYSDIR\Config.nt ;file where to replace
Call AdvReplaceInFile

SectionEnd

;------- Replace Function -------

Function AdvReplaceInFile
Exch $0 ;file to replace in
Exch
Exch $1 ;number to replace after
Exch
Exch 2
Exch $2 ;replace and onwards
Exch 2
Exch 3
Exch $3 ;replace with
Exch 3
Exch 4
Exch $4 ;to replace
Exch 4
Push $5 ;minus count
Push $6 ;universal
Push $7 ;end string
Push $8 ;left string
Push $9 ;right string
Push $R0 ;file1
Push $R1 ;file2
Push $R2 ;read
Push $R3 ;universal
Push $R4 ;count (onwards)
Push $R5 ;count (after)
Push $R6 ;temp file name

GetTempFileName $R6
FileOpen $R1 $0 r ;file to search in
FileOpen $R0 $R6 w ;temp file
StrLen $R3 $4
StrCpy $R4 -1
StrCpy $R5 -1

loop_read:
ClearErrors
FileRead $R1 $R2 ;read line
IfErrors exit

StrCpy $5 0
StrCpy $7 $R2

loop_filter:
IntOp $5 $5 - 1
StrCpy $6 $7 $R3 $5 ;search
StrCmp $6 "" file_write2
StrCmp $6 $4 0 loop_filter

StrCpy $8 $7 $5 ;left part
IntOp $6 $5 + $R3
IntCmp $6 0 is0 not0
is0:
StrCpy $9 ""
Goto done
not0:
StrCpy $9 $7 "" $6 ;right part
done:
StrCpy $7 $8$3$9 ;re-join

IntOp $R4 $R4 + 1
StrCmp $2 all file_write1
StrCmp $R4 $2 0 file_write2
IntOp $R4 $R4 - 1

IntOp $R5 $R5 + 1
StrCmp $1 all file_write1
StrCmp $R5 $1 0 file_write1
IntOp $R5 $R5 - 1
Goto file_write2

file_write1:
FileWrite $R0 $7 ;write modified line
Goto loop_read

file_write2:
FileWrite $R0 $R2 ;write unmodified line
Goto loop_read

exit:
FileClose $R0
FileClose $R1

SetDetailsPrint none
Delete $0
Rename $R6 $0
Delete $R6
SetDetailsPrint both

Pop $R6
Pop $R5
Pop $R4
Pop $R3
Pop $R2
Pop $R1
Pop $R0
Pop $9
Pop $8
Pop $7
Pop $6
Pop $5
Pop $4
Pop $3
Pop $2
Pop $1
Pop $0
FunctionEnd
____________________________________________________________


Hi all,

Just forget the last post. I find out wath the problem was.

Thx anyway