Verificar Éxito o Error de un Ping en VFP 6

142 views
Skip to first unread message

Juan Carlos M

unread,
Apr 23, 2021, 4:04:49 PM4/23/21
to Comunidad de Visual Foxpro en Español

En un programa realizo un Ping para verificar  si un servidor de actualizaciones responde o si nó usar otro server, pero he notado que FILETOSTR solo devuelve la primera linea del archivo hasta el último salto de línea, ¿ Es necesario utilizar un ciclo para analizar toda la salida del Ping o hay alguna manera de que se lea todo el archivo en una sola ocasión ?.

Gracias de Antemano.
Mi código es el siguiente:

If file('test.txt')
   Erase test.txt
endif
lcCmd = GetCommander() + ' ping ' + arrRecord[1] +  ' > test.txt'
Clear
? 'Using RUN command. Pinging localhost, wait...'
RUN /N7 &lcCmd

If file('test.txt')
   IF AT_C(FILETOSTR('test.txt'),'not find') > 0 .OR. AT_C(FILETOSTR('test.txt'),'timed out') > 0 
   ** REALIZA ALGO SI NO ALCANZA EL SERVER

Fernando Puyuelo Ossorio

unread,
Apr 26, 2021, 3:00:40 AM4/26/21
to Comunidad de Visual Foxpro en Español
PAra que sea más óptimo carga primero el contenido a una variable:
lcFile = FILTETOSTR(fichero)
Verifica que lcFile sí que ha cargado todo el contenido.

Creo que el problema es más en la ejecución del AT_C

Antonio Lima

unread,
Apr 26, 2021, 4:55:15 AM4/26/21
to publice...@googlegroups.com
Hola a todos,

Por si te sirve yo tengo este código,

*******************************************
FUNCTION ping
*******************************************
param tcServer
    LOCAL llResult
    tcServer = IIF( VARTYPE(tcServer)='C', ALLTRIM(tcServer), '')

    if empty(tcServer)
        return .f.
    endif

    DECLARE INTEGER WSACleanup IN ws2_32
    DECLARE INTEGER gethostbyname IN ws2_32 STRING host
    Declare Long inet_addr In wsock32 String cp
     DECLARE INTEGER WSAStartup IN ws2_32 INTEGER wVerRq, STRING lpWSAData
    Declare Long gethostbyaddr In wsock32 Long @addr, Long lenght, Long protocol

    IF WSAStartup(0x202, Repli(Chr(0),512)) = 0
        IF ISALPHA( LEFT(tcServer,1))
               llResult= !(gethostbyname(tcServer) = 0)
        ELSE
              * Ip-adress to NETWORK BYTE ORDRER
              ipAddress_n = inet_addr(alltrim(tcServer))
              llResult= !(gethostbyaddr(ipAddress_n,4,2)=0)
        ENDIF
    ENDIF
    = WSACleanup()

RETURN llResult

--
Visita el Blog de la Comunidad Visual FoxPro en Español: http://comunidadvfp.blogspot.com
---
Has recibido este mensaje porque estás suscrito al grupo "Comunidad de Visual Foxpro en Español" de Grupos de Google.
Para cancelar la suscripción a este grupo y dejar de recibir sus mensajes, envía un correo electrónico a publicesvfoxp...@googlegroups.com.
Para ver esta conversación en el sitio web, visita https://groups.google.com/d/msgid/publicesvfoxpro/aa8df198-0053-4513-b13f-d2f400ac249dn%40googlegroups.com.

Luis Maria Guayan

unread,
Apr 26, 2021, 4:39:41 PM4/26/21
to Comunidad de Visual Foxpro en Español
Hola Fernando, tanto tiempo de no leerte :-) Saludos amigo.

Luis María Guayán
Tucumán, Argentina
_______________________________

Comunidad Visual FoxPro en Español
http://comunidadvfp.blogspot.com
Reply all
Reply to author
Forward
0 new messages