Page 2 of 2 <12
Topic Options
#59436 - 2001-10-02 04:37 PM Re: How do you extract an EXACT string from a string or text file?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Jochen,
you can test by simulating the output from pv.exe to include the line NAV would produce. Here's the tail end of my C:\RC.TXT
code:

rtvscan.exe 1456
KIX32.EXE 2680
cmd.exe 2536
pv.exe 2376

But then, moot point, as I can't reproduce results of last night. Like I said, feels like a bad dream, only it wasn't.

p.s. I'm sticking with my invisible garbage theory.

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#59437 - 2001-10-02 05:06 PM Re: How do you extract an EXACT string from a string or text file?
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Les,

I had this once with a Registry entry called 'Software\Kerridge' and posted a question why the green F*** I was unable to modify these subkeys ... Bryce tested it on his Server (thanks mate) and said there's no problem with my Code ... it works.
So I tested his code (seemingly the very same ) and it worked on my system

The only thing different was that i wrote 'Kerrigde' in my snippet , and Bryce by accident the correct phrase 'Kerridge' ...
I spent 2 days on the whole action

J.

[edit]
btw... I will check this ... but maybe not today (we have to handle some aftermaths of the weekend)

[ 02 October 2001: Message edited by: jpols ]

_________________________



Top
#59438 - 2001-10-02 06:17 PM Re: How do you extract an EXACT string from a string or text file?
Jochen Administrator Offline
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 Offline
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 Offline
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 Offline
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 Administrator Offline
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 Offline
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
#59444 - 2001-10-26 09:19 PM Re: How do you extract an EXACT string from a string or text file?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
NTDOC,
Your nightmare is back... Kind'a like Groundhog Day... Should'a stuck with pipe to find...

Sorry... I couldn't resist.

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#59445 - 2001-10-26 09:36 PM Re: How do you extract an EXACT string from a string or text file?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Doc,

You're right - readline() returns a chr(0) when reading empty files (and I was using RC3 in my testing) ... would this be a suitable work-around (given that your reading a text file - should be no CHR(0)'s in there ?) :

code:

BREAK ON
$CHK = ""
$logfile = "C:\RC.TXT"
$ = OPEN(1,$logfile,2)
IF @error = 0
$x = readline(1)
?"@ERROR"
while @error = 0 and $x <> CHR(0)
if instr($x,"rtvscan.exe")
$CHK = "Running"
endif
$x = readline(1)
LOOP
$ = CLOSE(1)
ENDIF
?"CHK=$CHK"
EXIT 1

-Shawn

Or maybe, when you create the RC.TXT file, you can throw in an extra byte or two at the end (guarantee at least two in the file) and avoid this prob. altogether - say, by echo/appending some extra chars ?

[ 26 October 2001: Message edited by: Shawn ]

Top
#59446 - 2001-10-26 10:00 PM Re: How do you extract an EXACT string from a string or text file?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11625
Loc: CA
Thanks Shawn

Your right. The CHR(0) should not be in the file. The reason I ended up with a 0 byte file in the first place was becuase my code did not check and verify that the program was downloaded and run correctly. The shell created the file on its own without the program. Thus leaving me an empty file. This made me add more error checking in my code (a good thing I guess), had my code been better I might not have found this issue.

Your code does appear to function correctly with KiXtart v3.63 - What is different in 2001 RC3 that allows it to work with the previous code?

Top
#59447 - 2001-10-26 10:12 PM Re: How do you extract an EXACT string from a string or text file?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Not sure why this happens . I just think that you've found a new and wonderfull bug in 3.63. As well, this bug appears to have been fixed (either intentionally or as a side-effect) in KiXtart 2001. If I was to guess - I'd say that KiXtart is hickuping on the first readline of an empty file - and for some reason, not setting @ERROR to -1 (EOF) ... [shoulder shrug]

-Shawn

Top
#59448 - 2001-10-26 10:45 PM Re: How do you extract an EXACT string from a string or text file?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Shawn,
Your code without the CHR(0) check works fine in 3.62 against a zero byte file. Is it too late to report this 3.63 bug to development?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#59449 - 2001-10-27 08:37 PM Re: How do you extract an EXACT string from a string or text file?
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Hell !
Now I am confused !!!

Why did my code worked on my NT Box with 3.63
and a 0 byte file (created by Right mouse -> New -> Textfile ) ... I mean, I wouldn't have posted here untested !!!

Btw. my NT is an English one with SP6a

Please enlight ,
Jochen

_________________________



Top
#59450 - 2001-10-28 11:10 AM Re: How do you extract an EXACT string from a string or text file?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11625
Loc: CA
Don't know Jochen,

I'm at home with 2000 also. I'll try the code again on NT 4.0 SP6a when I get back to work on Tuesday. Your original code had problems working on my 2000 system using v3.63 but maybe it will work on NT 4.0

Hope your not upset Jochen, I am in no way accusing you of bad code or anything. In fact quite the opposite, I'm very greatful for the help in the first place. You have been quite helpful this time as well as many other times and I appreciate your help.

I'll let you know what I find on NT 4.0

[ 28 October 2001: Message edited by: NTDOC ]

Top
#59451 - 2001-10-29 02:17 PM Re: How do you extract an EXACT string from a string or text file?
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Doc,

mate, no definetly not upset !!!
Just dazed & confused

Jochen

_________________________



Top
#59452 - 2001-10-30 11:36 PM Re: How do you extract an EXACT string from a string or text file?
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Doc, Shawn,

I had to to do again with readlines in my Exchange struggle ... problem here xnet sometimes returns empty first lines

Finally managed to catch it (also killer-loop on 3.63) with :

code:

...
$x = readline(1)
if $x or asc($x) = chr(0)
loop the file ...
endif

Will verify on NT tomorrow ...


J.

_________________________



Top
#59453 - 2001-10-30 11:57 PM Re: How do you extract an EXACT string from a string or text file?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11625
Loc: CA
Hi Jochen,

The code sample does not appear to work on either NT4 or 2000 as is. Checking the CHAR(0) works though.

In your new post do you mean that readline is working different then Open File ?

Waiting to hear back...

Top
#59454 - 2002-08-10 03:24 AM Re: How do you extract an EXACT string from a string or text file?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
boys...
how you have managed without e-mail?

simple e-mail to ruud would have explained some or all of this...
_________________________
!

download KiXnet

Top
Page 2 of 2 <12


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

Who's Online
0 registered and 1574 anonymous users online.
Newest Members
BeeEm, min_seow, Audio, Hoschi, Comet
17882 Registered Users

Generated in 0.086 seconds in which 0.041 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