Page 1 of 1 1
Topic Options
#74791 - 2003-04-23 10:54 PM Strange Behavior
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Just playing today and found what I thought was a wierd behavior. I have an array of server names and need their IP addresses. "ping" was a handy way to resolve them. When I supplied one host name as a test it worked, but if I run the command more than once, it gives a wierd response.

First try - displays IP address
next try - displays result from prior shell command, newline, and IP of current server

Here's the code.. I'm at a loss to explain what's happening. Appreciate any ideas - in the mean time, I'll be looking for a UDF to accomplish this. (I figured a quick hack would suffice for this "throw-away" project.)

BTW - in troubleshooting, I've commented out most of the lines in the function. The prior response is printed as soon as the ReadLine is executed.

Thanks!

Glenn

code:
 
GetIP('server1')

GetIP('server2')

GetIP('server3')

Function GetIP($Host)

Dim $RTN, $RC $Line
$RTN = 1

Shell '%ComSpec% /c ping -n 1 $Host | %SystemRoot%\System32\Find "Pinging" > %TEMP%\junk.txt'

$RC = Open(5,"%TEMP%\junk.txt",2)
If @ERROR = 0
$Line = ReadLine(5)
$GetIP= Split(Join(Split($Line,']',-1),'['), '[')[1]
Del '%TEMP%\junk.txt'
$RTN = 0
$RC = Close(5)
EndIf

Exit $RTN

EndFunction



[ 23. April 2003, 23:00: Message edited by: Glenn Barnas ]
_________________________
Actually I am a Rocket Scientist! \:D

Top
#74792 - 2003-04-23 11:11 PM Re: Strange Behavior
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
PING() and WSHPING() would do this, too.

The delete won't work because your file is still labeled as open. You will need to close the file before deleting it.
_________________________
There are two types of vessels, submarines and targets.

Top
#74793 - 2003-04-23 11:44 PM Re: Strange Behavior
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Arrgh! Obvious - now!

Thanks - I've been staring at it for about 2 hours now.. really needed another set of eyes on it.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#74794 - 2003-04-24 03:18 PM Re: Strange Behavior
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You could train your new set of eye to check the UDF Library before writing your own function. It's much faster to copy an existing and tested UDF, though the learning experience is less [Wink]
_________________________
There are two types of vessels, submarines and targets.

Top
#74795 - 2003-04-24 10:45 PM Re: Strange Behavior
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Actually, I had Jochen's Ping UDF, but it was version 1.0 and had no formatting, making it tough to read and implement.. I grabbed his later (1.1) version and it worked great.

This started out as a "quick & dirty" tool to grab a couple of IP addresses from a small domain for use in migration planning.. didn't think that looking for a new(er) UDF would be worth the time.

BTW - I changed the code to close() the file immediately after the read and it failed exactly the same way. Wound up writing it anew just to try and figure out what was wrong and this time it worked. Still very strange. Maybe a wierd character in the file? The new code is nearly identical.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#74796 - 2003-04-25 09:23 AM Re: Strange Behavior
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Oh well,

it had formatting .. you just copied the code to the wrong editor, see : HOWTO: Submit code to / copy code from the board

The change from version 1.0 to version 1.1 was not that I submitted the code using Postprep but the use of FreeFileHandle() instead of using hardcoded handle 10, the first version works for me since years [Wink]

HTE
_________________________



Top
#74797 - 2003-04-25 09:42 AM Re: Strange Behavior
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
oh,
I see that the FAQ lacks something... might even add it myself...

anyway, if you want to preserve formatting on UDFs copied from KORG, you are better of with these:
http://www.gwspikval.com/jooel/UDF
http://kixhelp.com/udfs

the kixhelp.com mirror updates not so frequently as my site which is automated.

benefits also is easy search-engine and by author and alphabetical listings.

with these sites, it does not matter if you have whatever editor, even notepad (like myself)
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 640 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.055 seconds in which 0.024 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