Page 1 of 2 12>
Topic Options
#152814 - 2005-12-05 10:56 AM Erroneous zeros in the log file
AstaaLavista Offline
Starting to like KiXtart

Registered: 2005-08-11
Posts: 111
Loc: Gujarat, India.
Hi All,
I have written a function which writes all the errors generated into an ERROR LOG instead of displaying it on the screen.
Code:
 
Function LogErrors($ErrorValue, optional $MiscInfo1, optional $MiscInfo2)

If RedirectOutput($ErrorFile) = 0
If $ErrorValue = $ERROR_ACCESS_DENIED
? "Access is Denied for computer $MiscInfo1"
Else If $ErrorValue = $ERROR_BAD_NETPATH
? "The network path was not found for the computer $MiscInfo1"
Else
? "File not opened, error code: [" + $ErrorValue + "]"
If $MiscInfo1 > 0
? $MiscInfo1
EndIf
EndIf
EndIf

EndFunction




BUT the surprising thing that in the error statements, some ZEROS also got appended. (I don't know how )

here's a partial error log:


The network path was not found for the computer compname129A0
Access is Denied for computer compname129B00

First statement has 1 zero while 2nd statement has 2 zeros.
How are these zeros getting appended. Plz. let me know.

N.B. $ErrorFile is the name of the Error File.
Thank you.

Top
#152815 - 2005-12-05 11:03 AM Re: Erroneous zeros in the log file
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
U use redirectoutput. This will redirect all screen output to the file you specified.
Adding $rc = in front of all the commands/functions in the script, check if they are not 0 (no error all OK) and if so write to the log file would solve your problems.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#152816 - 2005-12-05 11:31 AM Re: Erroneous zeros in the log file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
instead of doing this complex error reporting UDF, why don't you just display the errors after each of the functions and commands.
if you want errorlog udf, something simple as the one below should do exactly what you already do:
Code:

function LogErrors()
if @error
$errorString = @wksta + "--> " + @serror + " (" + @error + ")"
$=RedirectOutput($ErrorFile)
$errorString ?
endif
endfunction

_________________________
!

download KiXnet

Top
#152817 - 2005-12-05 12:23 PM Re: Erroneous zeros in the log file
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
...but don't forget to redirect output back to the console when you're done.
Top
#152818 - 2005-12-05 12:57 PM Re: Erroneous zeros in the log file
AstaaLavista Offline
Starting to like KiXtart

Registered: 2005-08-11
Posts: 111
Loc: Gujarat, India.
Quote:

instead of doing this complex error reporting UDF, why don't you just display the errors after each of the functions and commands.
if you want errorlog udf, something simple as the one below should do exactly what you already do:
Code:



function LogErrors()
if @error
$errorString = @wksta + "--> " + @serror + " (" + @error + ")"
$=RedirectOutput($ErrorFile)
$errorString ?
endif
endfunction






Thank you for the help. It is far better than my function. I have to learn a lot. BUT still I am getting the same problem. I am still getting ZEROS in the log file.

Should I put
Code:
 
$rc = ? "File not opened, error code: [" + $ErrorValue + "]"
If NOT $rc=0
? $rc
EndIf



BUT this gives me an error.
Plz. let me know what is missing?

Top
#152819 - 2005-12-05 01:02 PM Re: Erroneous zeros in the log file
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Code:

If @ERROR = "0"
;do not write to file
Else
;write to file code goes here
EndIf

_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#152820 - 2005-12-05 01:23 PM Re: Erroneous zeros in the log file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
k, if you don't want the extra non-silenced zeros, use this version:
Code:

function LogErrors()
if @error
$errorString = @wksta + "--> " + @serror + " (" + @error + ")"
$=RedirectOutput($ErrorFile)
$errorString ?
$=RedirectOutput("")
endif
endfunction

_________________________
!

download KiXnet

Top
#152821 - 2005-12-05 03:23 PM Re: Erroneous zeros in the log file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
There are several FAQs on that topic.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#152822 - 2005-12-06 08:30 AM Re: Erroneous zeros in the log file
AstaaLavista Offline
Starting to like KiXtart

Registered: 2005-08-11
Posts: 111
Loc: Gujarat, India.
Quote:

k, if you don't want the extra non-silenced zeros, use this version:
Code:

function LogErrors()
if @error
$errorString = @wksta + "--> " + @serror + " (" + @error + ")"
$=RedirectOutput($ErrorFile)
$errorString ?
$=RedirectOutput("")
endif
endfunction






Thanks a lot for the code, Joel.
It has removed all the zeros from the log file, BUT i dont know why does it still print zeros on the CONSOLE.


Here's the code. (I have written a script to check a registry key of some computers. either the computer name can be mentioned in the script itself or it can be read from an input file)

Code:
 
CLS
;Debug On
Break On

$NotInstalled = "Not Installed.log"
$Installed = "Installed.log"
$ErrorFile = "Errors.log"
$InputFile = "computerlist.txt"

$RegistryValue = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Exchange\Client\Options'
$RegistryKey = 'DumpsterAlwaysOn'
$RegData = '01'

$FileNames = $Installed, $NotInstalled, $ErrorFile
For Each $Item In $FileNames
If Exist($Item)
Del $Item
EndIf
Next


;THIS IS THE LIST OF COMPUTERS FOR WHICH REGISTRY HAS TO BE CHECKED


$ComputerName1 = 'COMPUTER1'
$ComputerName2 = 'COMPUTER2'
$ComputerName3 = 'COMPUTER3'
$ComputerName4 = 'COMPUTER4'

$CompNames = $ComputerName1, $ComputerName2, $ComputerName3, $ComputerName4
For Each $Item In $CompNames
CheckRegValue($Item)
Next


;THE LIST OF COMPUTERS HAS ALSO BEEN MENTIONED IN A .TXT FILE


/*
If Open(3, $InputFile) = 0
$x = ReadLine(3)
While @ERROR = 0
;? "Line read: [" + $x + "]"
CheckRegValue($x)
$x = ReadLine(3)
Loop
Close (3)
Else
Beep
$msg=messagebox("$InputFile not accessible","Check Registry key",0)
;LogErrors(@ERROR,"Input File not accessible")
EndIf
*/

Function CheckRegValue($Item)

$Value = '\\' + $Item + '\' + $RegistryValue


$VersionType = ReadValue($Value,$RegistryKey)
;$msg=messagebox("$VersionType,"version type",0)

If @ERROR=0
;$msg=messagebox($VersionType,"version type",0)
Else
LogErrors(@ERROR,$Item)
EndIf

If VAL($VersionType) = VAL($RegData)

$Handle1 = FreeFileHandle()
If Open( $Handle1 , $Installed , 5 ) = 0
$z = WriteLine($Handle1,@CRLF + $Item)
Close ($Handle1)
;Else
;? "failed to open file $Installed with Handle1, error code : [" + @ERROR + "]"
EndIf

Else

$Handle2 = FreeFileHandle()
If Open( $Handle2 , $NotInstalled , 5 ) = 0
If $VersionType = ""
$VersionType ='N/A'
EndIf
$z = WriteLine($Handle2,@CRLF + $Item + " --> " + " Registry key is: " + $VersionType)
Close ($Handle2)
;Else
;? "failed to open file $NotInstalled with Handle2, error code : [" + @ERROR + "]"
EndIf
EndIf

EndFunction


Function LogErrors($ErrorValue, optional $MiscInfo1, optional $MiscInfo2)


If @ERROR
$errorString = $MiscInfo1 + "--> " + @serror + " (" + @error + ")"
$=RedirectOutput($ErrorFile)
$errorString ?
$=RedirectOutput("")
EndIf

EndFunction




one more thing, if a computer is NOT connected to the network, it takes around 30 seconds to display the reason. Is there any method of reducing this delay.

ReadValue function does not specify any time for pinging to a computer.
Thank you

Top
#152823 - 2005-12-06 08:42 AM Re: Erroneous zeros in the log file
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
Just quickly scanning your code, you have some "close"(s) that are not being handled.

try: $rc=close(1)
_________________________
(... better days ahead)

Top
#152824 - 2005-12-06 09:15 AM Re: Erroneous zeros in the log file
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
This isn't that kind of board. Please take your Erogenous zeros elsewhere... OH! You said erroneous, sorry my mistake.

 

Any coding you do that will produce output to the screen must be taken into consideration and handled.

Typically assigning the output to a variable will take care of the issue. Please review the FAQ here on the board for further information on this subject.
 

Top
#152825 - 2005-12-06 12:59 PM Re: Erroneous zeros in the log file
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Quote:


....
It has removed all the zeros from the log file, BUT I don’t know why does it still print zeros on the CONSOLE.
....





Did you read my first post? Guess not cause it shows $rc = in front of the commands/function you use to catch the error/return codes they give.

Why does the console display zeros and ones (amongst others)?
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#152826 - 2005-12-06 01:01 PM Re: Erroneous zeros in the log file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
and, they are not really erreneous, like said way before.
if you don't silence your function calls, kixtart reads it that you WANT to spill the 0's to the console.
_________________________
!

download KiXnet

Top
#152827 - 2005-12-06 01:08 PM Re: Erroneous zeros in the log file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
and mart was faster again...
_________________________
!

download KiXnet

Top
#152828 - 2005-12-06 01:34 PM Re: Erroneous zeros in the log file
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#152829 - 2005-12-07 12:20 AM Re: Erroneous zeros in the log file
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Quote:

and mart was faster again...




His wife may not like that...

Top
#152830 - 2005-12-07 09:58 AM Re: Erroneous zeros in the log file
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Quote:

Quote:

and mart was faster again...




His wife may not like that...




LOL

What wife? Not married.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#152831 - 2005-12-07 11:08 AM Re: Erroneous zeros in the log file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
and why is that?
_________________________
!

download KiXnet

Top
#152832 - 2005-12-07 11:11 AM Re: Erroneous zeros in the log file
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
LOL again
Dunno. I like it this way.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#152833 - 2005-12-07 11:13 AM Re: Erroneous zeros in the log file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
and it's nothing about you being too fast?

I know I have a habit of being way too fast...
_________________________
!

download KiXnet

Top
Page 1 of 2 12>


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

Who's Online
0 registered and 1110 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.044 seconds in which 0.016 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org