Page 1 of 1 1
Topic Options
#212652 - 2017-08-31 11:54 AM [SOLVE] take a string in flag file to use in variable in my script
Crayven Offline
Fresh Scripter

Registered: 2016-12-27
Posts: 5
Loc: France / Le Mans
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


Edited by Crayven (2017-08-31 03:02 PM)
_________________________
It is at the foot of the wall that one sees best the wall

Top
#212653 - 2017-08-31 11:57 AM Re: take a string in flag file to use in variable in my script [Re: Crayven]
Crayven Offline
Fresh Scripter

Registered: 2016-12-27
Posts: 5
Loc: France / Le Mans
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!
_________________________
It is at the foot of the wall that one sees best the wall

Top
#212654 - 2017-08-31 12:07 PM Re: take a string in flag file to use in variable in my script [Re: Crayven]
Crayven Offline
Fresh Scripter

Registered: 2016-12-27
Posts: 5
Loc: France / Le Mans
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
_________________________
It is at the foot of the wall that one sees best the wall

Top
#212655 - 2017-08-31 02:56 PM Re: take a string in flag file to use in variable in my script [Re: Crayven]
Crayven Offline
Fresh Scripter

Registered: 2016-12-27
Posts: 5
Loc: France / Le Mans
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]



Edited by Crayven (2017-08-31 03:02 PM)
_________________________
It is at the foot of the wall that one sees best the wall

Top
#212656 - 2017-08-31 05:06 PM Re: take a string in flag file to use in variable in my script [Re: Crayven]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
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 $

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 557 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.058 seconds in which 0.026 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org