Jump to content

Strange Effect Of Filereadline


Recommended Posts

Ok, I made this function to know if a computer is on or not.

Func _IsTheComputerOn ($computername)
 Local $ping
 RunWait(@comspec & " /c ping "& $computername &" -n 1 -w 50>"& @tempdir &"\ping.tmp","",@sw_hide)
 $ping = FileReadLine(@tempdir &"\ping.tmp",7);<<--- Here my problem
;MsgBox(0,"",$ping)  ;------------------------------------De-comment this to see...
 FileDelete(@tempdir &"\ping.tmp")
 If StringInStr($ping,"(0%") Then
  Return 1
 EndIf
Return 0
EndFunc

Strangely enough my script do not read the 7th line but the 4th!

I order to take the right line I have to set 13... it is not a big deal, but I'd like to know why...

Here an example ping.tmp... (the number at beggining has been added for clarity)

1-
 2-Esecuzione di Ping michele.manghi.locale [192.168.0.101] con 32 byte di dati:
 3-
 4-Risposta da 192.168.0.101: byte=32 durata<10ms TTL=128
 5-
 6-Statistiche Ping per 192.168.0.101:
 7-    Pacchetti: Trasmessi = 1, Ricevuti = 1, Persi = 0 (0% persi),
 8-Tempo approssimativo percorsi andata/ritorno in millisecondi:
 9-    Minimo = 0ms, Massimo =  0ms, Medio =  0ms
10-

mmm... When I pasted the file from Notepad :whistle: it added some blank lines making the line I speak of really the 13th... B)

Please,explain me what is going on...

Edited by ezzetabi
Link to comment
Share on other sites

Known problem with Microsoft ping. It puts an extra CR at the end of each line. Some applications ignore it; others treat it (wrongly) as an empty line. Notepad seems to be one of those. So does AutoIt!

I wonder who wrotre Microsoft ping...

Edited by ben_josephs
Link to comment
Share on other sites

Guest Cubex

Sorry once more all :whistle:

Func _IsTheComputerOn ($computername)
Local $ping
$pingtmp=@tempdir &"\ping.tmp"
RunWait(@comspec & " /c ping "& $computername &" -n 1 -w 50>"& $pingtmp,"",@sw_hide)
$ping = FileReadLine($pingtmp,13)
;MsgBox(0,"",$ping) ;------------------------------------De-comment this to see...
FileDelete($pingtmp)
If StringInStr($ping,"100%") Then
   Return 0
Else
   Return 1
EndIf
EndFunc
Link to comment
Share on other sites

Guest kotschi

@cubex: maybe you could use a better tool for 'pinging'...

"ALIVE"

http://wettberg.home.texas.net/alive.htm

which returns different ERRORLEVEL for the net-status:

Request timed out : ERRORLEVEL 1

Destination host unreachable : ERRORLEVEL 2

Destination network unreachable : ERRORLEVEL 3

Destination protocol unreachable : ERRORLEVEL 4

Destination port unreachable : ERRORLEVEL 5

Hardware error : ERRORLEVEL 6

TTL expired in transit : ERRORLEVEL 7

Bad Destination : ERRORLEVEL 8

Other errors : ERRORLEVEL 255

I only need this tool for finding out if a pc is online in our network...

:whistle:

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...