#23222 - 2002-06-14 04:33 PM
ReadLine and @ERROR
|
FTPMonster
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. 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. What did I do wrong this time?
|
|
Top
|
|
|
|
#23223 - 2002-06-14 04:38 PM
Re: ReadLine and @ERROR
|
Richard H.
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
|
|
Top
|
|
|
|
#23227 - 2002-06-14 04:44 PM
Re: ReadLine and @ERROR
|
Richard H.
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
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!]](images/icons/shocked.gif) [ 14 June 2002, 16:45: Message edited by: FTPMonster ]
|
|
Top
|
|
|
|
#23230 - 2002-06-14 04:51 PM
Re: ReadLine and @ERROR
|
FTPMonster
Fresh Scripter
Registered: 2002-05-30
Posts: 16
|
Sorry about that Richard, I'm a bit distracted at work.
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
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
LOL
Yeah, use the script I included in my second post
ROFL
|
|
Top
|
|
|
|
#23232 - 2002-06-14 05:08 PM
Re: ReadLine and @ERROR
|
FTPMonster
Fresh Scripter
Registered: 2002-05-30
Posts: 16
|
Richard, you are a god. Has anyone told you that before? I will now proceed to sacrifice a CD full of other scripting languages on an altar in your name.
|
|
Top
|
|
|
|
#23233 - 2002-06-14 05:13 PM
Re: ReadLine and @ERROR
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
What, no virgins?
You're welcome anyhow.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 735 anonymous users online.
|
|
|