Crayven
(Fresh Scripter)
2017-08-31 11:54 AM
[SOLVE] take a string in flag file to use in variable in my script

I search to use 2 string in file "flag.txt" to use in variable in my script:

i have a file "flag.txt":
 Quote:
;variable page acceuil a remplacer
acceuilorigine ="http://www.google.com"
; variable de la nouvelle page d'acceuil
newacceuil ="https://mywork.com"


I want take a string "http://www.google.com" in variable $acceuilori and "https://mywork.com" in $newaccueil in my script for change start page of IE,Chrome and Firefox.

i have test with .bat but no result.

Can you help me?
i found this but i don't know how to use that:
 Quote:
IF Open(3, "d:\testflag\testflag.kix") = 0
$x = ReadLine(3)
WHILE @ERROR = 0
? "Line read: [" + $x + "]"
$x = ReadLine(3)
LOOP
Close (3)
ELSE
BEEP
? "Config file not opened, error code: [" + @ERROR + "]"
ENDIF


Crayven
(Fresh Scripter)
2017-08-31 11:57 AM
Re: take a string in flag file to use in variable in my script

my test come with that in bat:
 Quote:
For /f "tokens=2 delims==",%%a in (%VAR%) do (
echo %%a
set accueilori = %%a
@echo %accueilori%
)

but don t work!


Crayven
(Fresh Scripter)
2017-08-31 12:07 PM
Re: take a string in flag file to use in variable in my script

in resume, in my script:

how to read line 2 after "=" to put the value in variable $acceuilori
and read line 4 after "=" to put the value in variable $newacceuil


Crayven
(Fresh Scripter)
2017-08-31 02:56 PM
Re: take a string in flag file to use in variable in my script

I make that but the end to cut $var and it work:
 Quote:
IF Open(3, "d:\testflag\flag.txt") = 0
$x = ReadLine(3)
WHILE @ERROR = 0
;redirige dans $var pour le decoupage apres les "="
$var = $var + $x
$x = ReadLine(3)
LOOP
Close (3)
ELSE
BEEP
? "Config file not opened, error code: [" + @ERROR + "]"
ENDIF
? "$var "
; ce qui suit ne fonctionne pas ....
$accueilori=split($var[1],'=')[1]
$newaccueil=split($var[1],'=')[3]



ShaneEP
(MM club member)
2017-08-31 05:06 PM
Re: take a string in flag file to use in variable in my script

Have you considered using an INI file, instead of a text file? The built in INI functions of kix would make this much easier.

flag.ini
 Quote:
[FLAGS]
acceuilorigine = "http://www.google.com"
newacceuil = "https://mywork.com"


KiX Script
 Code:
$flagFile = @ScriptDir + "\flag.ini"

If Exist($flagFile)
   $acceuilori = ReadProfileString($flagFile, "FLAGS", "acceuilorigine")
   $newaccueil = ReadProfileString($flagFile, "FLAGS", "newacceuil")
Endif

? $acceuilori
? $newaccueil

get $