Page 1 of 1 1
Topic Options
#23222 - 2002-06-14 04:33 PM ReadLine and @ERROR
FTPMonster Offline
Fresh Scripter

Registered: 2002-05-30
Posts: 16
Previously I posted that I wanted to have a list of drive mappings put into a messagebox. Everyone was very helpful to me, and I got a login script working and it looks great. [Big Grin]
Problem is, on NT4 there are IPC$ connections listed from USE LIST. I don't want to confuse the users, so I tried to remove the IPC lines out when I read the file. Here's the script I have now:

Break on
$tempfile = "C:\templist.txt"
$x = 0
$line = ""
Del $tempfile
$rc = ReDirectOutput($tempfile)
Use list
$rc = ReDirectOutput("")
If Open(1,$tempfile) = 0
While @ERROR = 0
if InStr($line, "IPC$") = 0
$line = $line + ReadLine(1) + Chr(10) + Chr(13)

endif
Loop
$rc = Close(1)
EndIf
messagebox($line, "Title", 0, 60)

It seems to hang in the InStr section. My uneducated guess is @ERROR is no longer 0 when it finds that line and throws the system into an endless loop.
[Confused] What did I do wrong this time? [Confused]

Top
#23223 - 2002-06-14 04:38 PM Re: ReadLine and @ERROR
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
No, the problem is that if your InStr() doesn't evaluate to TRUE you will never do the readline(1) in your conditional.

This means you will be stuck with the same line (and no @ERROR) for eternity [Wink]

Top
#23224 - 2002-06-14 04:39 PM Re: ReadLine and @ERROR
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Without testing your code...
One thing jumps out at me. When $ is used in quotes, it should be $$.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#23225 - 2002-06-14 04:41 PM Re: ReadLine and @ERROR
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
It would be much easier to read if you pasted inside CODE tags so that indenting were preserved.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#23226 - 2002-06-14 04:43 PM Re: ReadLine and @ERROR
Schuliebug Offline
Hey THIS is FUN
*****

Registered: 2002-01-18
Posts: 379
Loc: Netherlands
I would have said: 'Could you try it also with IPC$$ (note the double $) ?', but Howard has already the solution !
_________________________
Kind regards,

Top
#23227 - 2002-06-14 04:44 PM Re: ReadLine and @ERROR
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
...and here is a working one I prepared earlier...
code:
Break on
$tempfile = "C:\templist.txt"
$Display = ""
Del $tempfile
$rc = ReDirectOutput($tempfile)
Use list
$rc = ReDirectOutput("")
If Open(1,$tempfile) = 0
$line=ReadLine(1)
While @ERROR = 0
If InStr($line, "IPC$$") = 0
$Display = $Display + $line + Chr(10) + Chr(13)
EndIf
$line=ReadLine(1)
Loop
$rc = Close(1)
EndIf
messagebox($Display, "Title", 0, 60)


Top
#23228 - 2002-06-14 04:44 PM Re: ReadLine and @ERROR
FTPMonster Offline
Fresh Scripter

Registered: 2002-05-30
Posts: 16
OK, new attempt with code:
code:
  
Break on
$tempfile = "C:\templist.txt"
$x = 0
$line = ""
Del $tempfile
$rc = ReDirectOutput($tempfile)
Use list
$rc = ReDirectOutput("")
If Open(1,$tempfile) = 0
While @ERROR = 0
if InStr($line, "IPC$$") = 0
$line = $line + ReadLine(1) + Chr(10) + Chr(13)
endif
Loop
$rc = Close(1)
EndIf

As you can tell, I threw in the $$. Turns out when I did a mini-test where it just echoed to screen and not into a variable the single $ worked fine. [Eek!]

[ 14 June 2002, 16:45: Message edited by: FTPMonster ]

Top
#23229 - 2002-06-14 04:46 PM Re: ReadLine and @ERROR
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
No, it won't work.

Please re-read my first post.

Top
#23230 - 2002-06-14 04:51 PM Re: ReadLine and @ERROR
FTPMonster Offline
Fresh Scripter

Registered: 2002-05-30
Posts: 16
Sorry about that Richard, I'm a bit distracted at work. [Big Grin]

Since it won't evaluate because of that InStr, is there a way around this?

Top
#23231 - 2002-06-14 05:00 PM Re: ReadLine and @ERROR
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
LOL

Yeah, use the script I included in my second post

ROFL [Big Grin]

Top
#23232 - 2002-06-14 05:08 PM Re: ReadLine and @ERROR
FTPMonster Offline
Fresh Scripter

Registered: 2002-05-30
Posts: 16
Richard, you are a god. Has anyone told you that before? [Big Grin]
I will now proceed to sacrifice a CD full of other scripting languages on an altar in your name. [Big Grin] [Big Grin] [Big Grin]

Top
#23233 - 2002-06-14 05:13 PM Re: ReadLine and @ERROR
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
What, no virgins? [Frown]

You're welcome anyhow.

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 823 anonymous users online.
Newest Members
JimDunn, fgarcia, Viginette, ManuvdWielNL, Sir_Barrington
17890 Registered Users

Generated in 0.06 seconds in which 0.022 seconds were spent on a total of 12 queries. Zlib compression enabled.

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