Technical support and scripting issues
Moderators: Dorian (MJT support), JRL
-
GarryP
- Junior Coder
- Posts: 27
- Joined: Sat Feb 04, 2006 12:01 pm
Post
by GarryP » Wed Jul 11, 2012 4:04 pm
I do not completely understand how to use STDOUT. Sorry if this is discussed somewhere but I have searched and cannot find anything more than cursory information. I am calling this sample compiled script from another app that monitors output, and it always reads the exit code=0. What am I doing wrong. I am sure I will be embarrassed with how easy it is, but right now I am simply confused. Thanks, Garry
Code: Select all
Function IsAlive(strHost)
'---------- Test to see if host or url alive through ping -----------------
' Returns True if Host responds to ping
'
' Though there are other ways to ping a computer, Win2K,
' XP and different versions of PING return different error
' codes. So the only reliable way to see if the ping
' was sucessful is to read the output of the ping
' command and look for "TTL="
'
' strHost is a hostname or IP
Const OpenAsASCII = 0
Const FailIfNotExist = 0
Const ForReading = 1
Dim objShell, objFSO, sTempFile, fFile
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
sTempFile = objFSO.GetSpecialFolder(2).ShortPath & "\" & objFSO.GetTempName
objShell.Run "%comspec% /c ping.exe -n 2 -w 500 " & strHost & ">" & sTempFile, 0 , True
Set fFile = objFSO.OpenTextFile(sTempFile, ForReading, FailIfNotExist, OpenAsASCII)
Select Case InStr(fFile.ReadAll, "TTL=")
Case 0
IsAlive = "10"
Case Else
IsAlive = "1"
End Select
fFile.Close
objFSO.DeleteFile(sTempFile)
Set objFSO = Nothing
Set objShell = Nothing
End Function
VBEND
Let>htp=192.168.1.8
Length>htp,lhosttoping
If>lhosttoping=3
MDL>Send Parameters eg. thisapp /htp=192.168.1.1
Else>
VBEval>IsAlive("%htp%"),result
SOWrite>result
EndIf>
-
GarryP
- Junior Coder
- Posts: 27
- Joined: Sat Feb 04, 2006 12:01 pm
Post
by GarryP » Thu Jul 12, 2012 12:52 am
I knew it would make sense once I figured it out. I run the compiled console app with the syntax of C:\mycompiledapp.exe /htp=192.168.1.1 and if ping is successful I receive an exit code of 0, anything else and I receive an exit code of 99. Thanks, Garry
Code: Select all
VBSTART
Function IsAlive(strHost)
'---------- Test to see if host or url alive through ping -----------------
' Returns True if Host responds to ping
'
' Though there are other ways to ping a computer, Win2K,
' XP and different versions of PING return different error
' codes. So the only reliable way to see if the ping
' was sucessful is to read the output of the ping
' command and look for "TTL="
'
' strHost is a hostname or IP
Const OpenAsASCII = 0
Const FailIfNotExist = 0
Const ForReading = 1
Dim objShell, objFSO, sTempFile, fFile
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
sTempFile = objFSO.GetSpecialFolder(2).ShortPath & "\" & objFSO.GetTempName
objShell.Run "%comspec% /c ping.exe -n 2 -w 500 " & strHost & ">" & sTempFile, 0 , True
Set fFile = objFSO.OpenTextFile(sTempFile, ForReading, FailIfNotExist, OpenAsASCII)
Select Case InStr(fFile.ReadAll, "TTL=")
Case 0
IsAlive = False
Case Else
IsAlive = True
End Select
fFile.Close
objFSO.DeleteFile(sTempFile)
Set objFSO = Nothing
Set objShell = Nothing
End Function
VBEND
Length>htp,lhosttoping
If>lhosttoping=3
MDL>Send Parameters eg. thisapp /htp=192.168.1.1
Else>
VBEval>IsAlive("%htp%"),phoneresult
EndIf>
If>pingresult=True
Exit>0
Else>
Exit>99
EndIf>