#59438 - 2001-10-02 06:17 PM
Re: How do you extract an EXACT string from a string or text file?
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
I'm terribly sorry , but I think I know what went wrong :To prevent a readline loop-o-death (EMPTY FILE) I once added the 'if $x - loop - endif' thing ... that naturally exit if the first line is empty  To make this thing bullet proof you have to add If $x or $x = crlf : code:
Break on ; *** Variables *** $CHK = "neither" $ChkNavService = '%comspec% /c %windir%\pv.exe -q >C:\RC.TXT' $StopNavService = 'NET STOP "Norton AntiVirus Client"' $StartNavService = 'NET START "Norton AntiVirus Client"' $cr = chr(13) + chr(10) ;SHELL $ChkNavService $logfile = "C:\Documents and Settings\Administrator\Desktop\RC.TXT" $ = open(1,$logfile,2) if @error = 0 $x = readline(1) if $x or asc($x) = $cr do select case instr($x,"rtvscan.exe") $CHK = "NAVNT" case instr($x,"rtvscn95.exe") $CHK = "NAV9X" endselect $x = readline(1) until @error endif endif $ = close(1) select case $CHK = "NAVNT" ? "NAV is "$CHK ? "This should say NAVNT" case $CHK = "NAV9X" ? "NAV is "$CHK ? "This should say NAV9X" case 1 ;unknown problem ? "NAV is "$CHK ? "This should say neither. File entry was not found" endselect get $
worked for me , also if 1st line was empty Jochen [ 02 October 2001: Message edited by: jpols ]
_________________________
|
Top
|
|
|
|
#59439 - 2001-10-02 07:52 PM
Re: How do you extract an EXACT string from a string or text file?
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11625
Loc: CA
|
Bad Dream - Yes... Well I'm lost even more now. Les, your code works today for me as well. Don't know why! Jochen, Thanks for the explanation. No apology needed. I asked and you supplied, then you worked on it to make sure it worked as I needed it. Thanks again. Sorry about not much weekend posting stuff, but my social life with the girlfriend/fiance was starting to get in trouble. If you noticed all my posts have slowed so I don't end up in the Dog House. Thanks again to everyone for helping with this. Now all I need to do is finish up some other pieces of the code and test it on some of my 95/98/ME/2000/XP systems. I'll post an update hopefully soon as to the outcome. Cheers
|
Top
|
|
|
|
#59440 - 2001-10-26 04:30 AM
Re: How do you extract an EXACT string from a string or text file?
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11625
Loc: CA
|
Hi Jochen and/or others members...I have another question about this parsing. If the file size is 0 it keeps looping. If it is empty except for a carriage return then it is okay. How can I prevent the looping when the file size is 0 ? I added checking code, but is it possible some other way in the looping code? code:
$CHK = "Unknown" BREAK ON $Fsize = GETFILESIZE ("C:\RC.TXT") IF $Fsize = 0 ?"File size $Fsize is too small to work with." GOTO END ELSE ?"File size $Fsize is okay to work with." GOSUB TEST ? "Hello... were back now. " ? "The CHK value is: " $CHK ENDIF:TEST ; Checks if the NAV Service is running on Windows NT/2000/XP systems. $logfile = "C:\RC.TXT" $ = OPEN(1,$logfile,2) IF @error = 0 $x = readline(1) IF $x OR asc($x) = $crlf DO SELECT CASE instr($x,"rtvscan.exe") $CHK = "Running" ENDSELECT $x = readline(1) UNTIL @error ENDIF ENDIF $ = CLOSE(1) RETURN :END
|
Top
|
|
|
|
#59441 - 2001-10-26 05:09 AM
Re: How do you extract an EXACT string from a string or text file?
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Hey Doc, hows it going tonight bud ?This loop should give you eveything you're looking for - handles null (zero byte) files like a charm ... code:
BREAK ON $CHK = ""
$logfile = "C:\RC.TXT"
$ = OPEN(1,$logfile,2) IF @error = 0 $x = readline(1) while @error = 0 if instr($x,"rtvscan.exe") $CHK = "Running" endif $x = readline(1) LOOP $ = CLOSE(1) ENDIF
?"CHK=$CHK"
EXIT 1
-Shawn
|
Top
|
|
|
|
#59442 - 2001-10-26 01:25 PM
Re: How do you extract an EXACT string from a string or text file?
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
Doc, You should read my replies more attentive  the last reply I made was about the "empty-file-readline()-loop-o-death" The line in question is this one : code:
if $x or asc($x) = $cr ;where $cr equals a CRLF
It checks the first readline for contents or a Newline , and if there isn't, it don't continues , thus the Killer loop is prevent ... Jochen <edit>
Huhh , scary !!! And I should read your replies more attentive ... the problem you got is that $crlf is not defined ! place $crlf = chr(13) + chr(10) in the start of your script ! </edit> [ 26 October 2001: Message edited by: jpols ]
_________________________
|
Top
|
|
|
|
#59443 - 2001-10-26 09:12 PM
Re: How do you extract an EXACT string from a string or text file?
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11625
Loc: CA
|
Bummer - Things not that good here Shawn. Many good people have left or been laid off here at the Mouse.Sorry Jochen, My real script has the $CRLF defined. I have tested both of your scripts and both of them seem to go into an endless loop with a file size of Zero bytes. Code Sample 1
code:
$crlf = chr(13)+chr(10) ;chr(13) is a Carriage Return and chr(10) is a line feed $CHK = "Unknown" BREAK ON $logfile = "C:\RC.TXT" $ = OPEN(1,$logfile,2) IF @error = 0 $x = readline(1) IF $x OR asc($x) = $crlf DO SELECT CASE instr($x,"rtvscan.exe") $CHK = "Running" ENDSELECT $x = readline(1) UNTIL @error ENDIF ENDIF $ = CLOSE(1)
Code Sample 2
code:
BREAK ON$CHK = "" $logfile = "C:\RC.TXT" $ = OPEN(1,$logfile,2) IF @error = 0 $x = readline(1) while @error = 0 if instr($x,"rtvscan.exe") $CHK = "Running" endif $x = readline(1) LOOP $ = CLOSE(1) ENDIF ?"CHK=$CHK" EXIT 1
As I said before, if there is "anything" in the file the code works fine. If it has a size of at lest 2 bytes "a $cr" it works. If it has nothing it loops forever till you break out of it manually. I'm using KiXtart v3.63 on Windows 2000 Pro SP2 NOTE: I just now tested this on KiXtart 2001 RC3 and it works fine. It DOES NOT work on KiXtart v3.63 Is this a bug or some other known issue?
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1574 anonymous users online.
|
|
|