Nova Posted December 1, 2004 Share Posted December 1, 2004 Ok im still working on a solution for the same problem I posted about 2 days ago,ive been real busy and just found a few spare mins to give it another try ! The following code pings comp4 on my home network (Comp4 dose not exist) and saves the results into a txt file called Temp.txt Then it open temp.txt and reads the file Then it looks for the text "Ping request could not find host comp4" (I know that this text has to be present in the file Temp.txt because u get this reply when u ping a computer that dosent exist ) Problem code always returns "Text not found" ! RunWait(@ComSpec & " /c " & 'ping comp4 >> C:/Temp.txt', "", @SW_HIDE) $file = FileOpen("C:/Temp.txt", 0) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $Find = StringInStr( $file, "Ping request could not find host comp4" ) If $Find = 0 Then MsgBox(0, "Error", "Text not found") Else MsgBox(0, "Error", "Text found") EndIf FileClose($file) Exit 0 Im asuming that the line $Find = StringInStr( $file, "Ping request could not find host comp4" ) dosent actually search $file for the txt "ping request could not find host comp4" Anyone point out what im doing wrong ? Link to comment Share on other sites More sharing options...
ezzetabi Posted December 1, 2004 Share Posted December 1, 2004 (edited) I am not sure you were joking or not, but you where looking for text in the file handle... RunWait(@ComSpec & " /c " & 'ping comp4 >> C:/Temp.txt', "", @SW_HIDE) $file = FileRead("C:/Temp.txt", FileGetSize("C:/Temp.txt")) FileDelete('c:\temp.txt') If @error Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $Find = StringInStr( $file, "Ping request could not find host comp4" ) If $Find = 0 Then MsgBox(0, "Error", "Text not found") Else MsgBox(0, "Error", "Text found") EndIf ;FileClose($file) <-Sorry. Forgot. Still the mistake is YOURS. Exit 0 Edited December 2, 2004 by ezzetabi Link to comment Share on other sites More sharing options...
Nova Posted December 1, 2004 Author Share Posted December 1, 2004 (edited) Damit, I just opened the file, I never read it ! Cheers ezzetabi ! There was one line of code u wrote and I dont understand why its there ! FileGetSize("C:/Temp.txt") Why add this in I dont c a use in this case for it ? EDIT:Figured it out second parameter in file read is count (The number of characters to read) so using file get size as count tells file read to read the whole file. Edited December 1, 2004 by nova Link to comment Share on other sites More sharing options...
Nova Posted December 1, 2004 Author Share Posted December 1, 2004 (edited) FileClose($file)[Payback]I am not sure you were joking or not, but you tryed to close a file handle ! [/payback]When ur script is ran u get an error Error invalid file handle used Edited December 1, 2004 by nova Link to comment Share on other sites More sharing options...
Developers Jos Posted December 1, 2004 Developers Share Posted December 1, 2004 [Payback]I am not sure you were joking or not, but you tryed to close a file handle ! [/payback]When ur script is ran u get an error<{POST_SNAPBACK}>just remove this line:FileClose($file) SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Nova Posted December 1, 2004 Author Share Posted December 1, 2004 (edited) @Jedb I realised the problem with ezzetabi code and quickly fixed it !I woz just messn with him coz he pointed out my stupid mistake above with his comment I am not sure if you were joking or not, but you where looking for text in the file handle... So I commented on his stupid mistake with I am not sure if you were joking or not, but you tryed to close a file handle ! Twoz all in good fun Any ways the following works at least 10 times quicker when trying to figure out if a given computer is online !RunWait(@ComSpec & " /c " & 'net view >> C:/Temp.txt', "", @SW_HIDE) $file = FileRead("C:/Temp.txt", FileGetSize("C:/Temp.txt")) If @error Then Exit EndIf $Find = StringInStr( $file, "\\Comp4" ) If $Find1 = 0 Then MsgBox(0, "Info", "Comp4 is offline") Else MsgBox(0, "Info", "Comp4 is online") EndIf FileDelete('c:\temp.txt') Exit 0 Edited December 1, 2004 by nova Link to comment Share on other sites More sharing options...
ezzetabi Posted December 2, 2004 Share Posted December 2, 2004 Actually I remember you that the faulty script that tried to look for a string inside a filehandle is yours. I just forgot to remove that useless line. @Jbed, if I copy the script of my post in a scite buffer and press ALT+9 it does not actually tidy. Sometime certain lines, already wrongly indented, are ignored, it is just me? Link to comment Share on other sites More sharing options...
Developers Jos Posted December 2, 2004 Developers Share Posted December 2, 2004 @Jbed, if I copy the script of my post in a scite buffer and press ALT+9 it does not actually tidy.Sometime certain lines, already wrongly indented, are ignored, it is just me?<{POST_SNAPBACK}>can you give me an example script that doesn't tidy correctly ? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
ezzetabi Posted December 2, 2004 Share Posted December 2, 2004 As I said.RunWait(@ComSpec & " /c " & 'ping comp4 >> C:/Temp.txt', "", @SW_HIDE) $file = FileRead("C:/Temp.txt", FileGetSize("C:/Temp.txt")) FileDelete('c:\temp.txt') If @error Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $Find = StringInStr( $file, "Ping request could not find host comp4" ) If $Find = 0 Then MsgBox(0, "Error", "Text not found") Else MsgBox(0, "Error", "Text found") EndIf ;FileClose($file) <-Sorry. Forgot. Still the mistake is YOURS. Exit 0<{POST_SNAPBACK}> Link to comment Share on other sites More sharing options...
Developers Jos Posted December 2, 2004 Developers Share Posted December 2, 2004 As I said.<{POST_SNAPBACK}>Works fine for me when i run tidy on this code .... What settings do you have ? (can you show/PM me your Tidy.ini info ?) SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Batman Posted December 6, 2004 Share Posted December 6, 2004 Whats this tidy command thing, i think i need it. I always leave stupid things War does not determine who is right, it determines who is left. Link to comment Share on other sites More sharing options...
ezzetabi Posted December 6, 2004 Share Posted December 6, 2004 (edited) JdeB improved SciTe have a integrated command to tidy the scrips.I think can find also stand alone version in his pages.http://www.autoitscript.com/fileman/users/jdeb/jdeb_autoit_stuff.htm Edited December 6, 2004 by ezzetabi Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now