itdaddy
(Starting to like KiXtart)
2007-01-10 10:42 PM
@ERROR giving false positives?

Code:
$ThisMyArray
 For Each $Element In $ThisMyArray "PC1", "PC2", "PC3"

	  tcGetEvent($Element, $Task)  ; load the bad task data
          tcDefineTask("SUS=0")        ; (disable = 1, enable = 0)
          tcSetEvent($Element, $Task)  ; update the task on the target
          IF @ERROR <> 0
	       $RC = REDIRECTOUTPUT (failure.txt, 0)
	       ? $Element
	  Else if @ERROR = 0
	        $RC = REDIRECTOUTPUT (success.txt, 0)
	       ? $Element
	  Endif Endif

 Next


Hey anyone or Glenn,

I got this to work thanks so much. But my error trap works on all my other scripts but for somereason @ERROR keeps giving me false positves (back and forth whether a 0 or 1). Why? and how can I correct this. I like and need to see which PCs failed and which succeeded. This is crucial. Thanks guys

Happy New you to you all!


LonkeroAdministrator
(KiX Master Guru)
2007-01-10 11:16 PM
Re: @ERROR giving false positives?

actually, this:
Code:
$ThisMyArray
 For Each $Element In $ThisMyArray "PC1", "PC2", "PC3"


does not work at all.
your whole for-next loop is skipped.


Benny69
(MM club member)
2007-01-10 11:19 PM
Re: @ERROR giving false positives?

You have to define the array before you can use it:
Code:
$ThisMyArray = "PC1", "PC2", "PC3"
 For Each $Element In $ThisMyArray

	  tcGetEvent($Element, $Task)  ; load the bad task data
          tcDefineTask("SUS=0")        ; (disable = 1, enable = 0)
          tcSetEvent($Element, $Task)  ; update the task on the target
          IF @ERROR <> 0
	       $RC = REDIRECTOUTPUT (failure.txt, 0)
	       ? $Element
	  Else if @ERROR = 0
	        $RC = REDIRECTOUTPUT (success.txt, 0)
	       ? $Element
	  Endif Endif

 Next



itdaddy
(Starting to like KiXtart)
2007-01-11 08:01 AM
Re: @ERROR giving false positives?

yeah dudes; you are right; it was a type sorry my bad!

I was tired when I wrote that.!
THANKS!

DOES ANYONE KNOW WHY I am getting false positves? what i mean is.
I am not getting the correct error handling I am use to?
and it is not writing missed workstation names to the correct text file.
success.txt or failure.txt?
help


LonkeroAdministrator
(KiX Master Guru)
2007-01-11 10:07 AM
Re: @ERROR giving false positives?

well, you are not showing what is $task

anyway, this:
Code:
          IF @ERROR <> 0
	       $RC = REDIRECTOUTPUT (failure.txt, 0)
	       ? $Element
	  Else if @ERROR = 0
	        $RC = REDIRECTOUTPUT (success.txt, 0)
	       ? $Element
	  Endif Endif

is same as:
Code:
          IF @ERROR <> 0
	       $RC = REDIRECTOUTPUT (failure.txt, 0)
	       ? $Element
	  Else
	        $RC = REDIRECTOUTPUT (success.txt, 0)
	       ? $Element
	  Endif


Benny69
(MM club member)
2007-01-11 02:17 PM
Re: @ERROR giving false positives?

The @ERROR macro only contains the most recent error code, you are only checking for an error after the third function you are calling, you should be checking after each one. It would be easier for us to help you if you post the ENTIRE script and not expect us to try to guess what is happening.

Glenn BarnasAdministrator
(KiX Supporter)
2007-01-11 03:50 PM
Re: @ERROR giving false positives?

Of the 3 functions, the third is the one that you would want to monitor the return code from. I'd suggest adding "@SERROR ?" statements (without quotes) after EACH function to see what's happening.

Glenn


itdaddy
(Starting to like KiXtart)
2007-01-12 09:53 PM
Re: @ERROR giving false positives?

Code:
call "tcLib.kxf"

tcInit(1)

  ; just disable each PC on network
    $Task = "FSPinstall"


$ThisMyArray = "PC1", "PC2, "PC3"

For Each $Element In $ThisMyArray

	  tcGetEvent($Element, $Task)  ; load the bad task data
          tcDefineTask("SUS=0")       ; set it to Suspend (disable = 1, enable = 0)
          tcSetEvent($Element, $Task)  ; update the task on the target
         
	  IF @ERROR <> 0
	       $RC = REDIRECTOUTPUT (failure.txt, 0)
	       ? $Element
	  Else if @ERROR = 0
	        $RC = REDIRECTOUTPUT (success.txt, 0)
	       ? $Element
	  Endif Endif


 Next



Sorry, here it is and it works slick like (Glenn thanks). But it gives false positives and false negatives. I have this same error handling scheme for shell commands in Kixtart and it handles them correctly; I have tested it ushering failures to failure.txt and successes to success.txt. Could you explain a bit more on why (Glenn please)the errors traps are hit and miss. I think I understand what you say; can you detail it a bit more? Thanks
so much to you all for you help!
Thanks Jooel! Yeah, it is hard without entire code.

I made this cause i didnt want to go to each workstation behind the scense just to disable this task; script worked slick did what could have taken 1 hour took only 3 minutes! bam!!!!!!!!!! I love scripts!


Glenn BarnasAdministrator
(KiX Supporter)
2007-01-12 11:18 PM
Re: @ERROR giving false positives?

Try this:

Code:
; - Glenn - added debugging statements
; I don't indent debug code so I can remember it doesn't belong there!

call "tcLib.kxf"

tcInit(1)

; just disable each PC on network
$Task = "FSPinstall"

$ThisMyArray = "PC1", "PC2, "PC3"

$RC = RedirectOutput('c:\temp\status.log')

For Each $Element In $ThisMyArray

'PC is ' $Element ?

	  tcGetEvent($Element, $Task)  ; load the bad task data
'GetEvent returned: ' @SERROR ?
'Task Array contains:' ?
For $I = 0 to 20
  $I ' ' $a_tcTASK[$I] ?
Next

          tcDefineTask("SUS=0")       ; set it to Suspend (disable = 1, enable = 0)
'DefineTask returned: ' @SERROR ?
'Task Array contains:' ?
For $I = 0 to 20
  $I ' ' $a_tcTASK[$I] ?
Next

'Compare the before/after values! Enter to continue: ' Gets $ ?

          tcSetEvent($Element, $Task)  ; update the task on the target
  ; Need to capture the errors here, since RedirectOutput will change them!
  $EC = @ERROR
  $ES = @SERROR
'SetEvent returned: ' $ES ?


  $Element ' - ' $EC ' - ' $ES ?
 Next

$RC = RedirectOutput('')



Then examine the resulting log file to see what happened. You can even post it here.

Glenn


itdaddy
(Starting to like KiXtart)
2007-01-12 11:22 PM
Re: @ERROR giving false positives?

Code:
call "tcLib.kxf"

tcInit(1)

  ; just disable each PC on network
    $Task = "FSPinstall"


$ThisMyArray = "ftran1", "ftran2", "ftran3"

For Each $Element In $ThisMyArray

	  tcGetEvent($Element, $Task)  ; load the bad task data
          @SERROR ?
	  
	  tcDefineTask("SUS=0")       ; set it to Suspend (disable = 1, enable = 0)
          @SERROR ?
	  
	  tcSetEvent($Element, $Task)  ; update the task on the target
          @SERROR ?

	  ;IF @ERROR <> 0
	  ;     $RC = REDIRECTOUTPUT (failure.txt, 0)
	  ;     ? $Element
	  ; Else if @ERROR = 0
	  ;      $RC = REDIRECTOUTPUT (success.txt, 0)
	  ;     ? $Element
	  ; Endif Endif
sleep 30

 Next




Glenn, I did what you said and the message out was (The operation completed successfully). This means that @ERROR = 0 correct and if it @ERROR = 1 then it should say it failed. All three functions SUCCESSFUL?
So why doesn't this work well. It doesn't work. I tried it. With ftran2. I shut the workstation off to see if it would usher failed workstation names to the failure.txt? sometime its worked other times they all went into the failure.txt bucket even though all of them succeeded?

So why is it not doing what normally works in this scheme. It does work on my other script where it maps the drive and upon success or failure adds workstation names accordingly? thanks.

Yes, guys I know the error trap is commented out for a reason this time.
Thanks if you guys try to correct me. Thanks



LonkeroAdministrator
(KiX Master Guru)
2007-01-12 11:49 PM
Re: @ERROR giving false positives?

uhm. but you still keep the double "if" there?
horrifying.


itdaddy
(Starting to like KiXtart)
2007-01-14 12:25 AM
Re: @ERROR giving false positives?

Jooel
what is so horrifying about that? It works on all my other applications
just perfectly. What is the big deal. if it works, then code it!
you can code anything different. that is what makes coding cool.
everyone has a style and i am just finding mine!

do you have any suggestions besides "horrifying?"

i guess you must be an expert error trapper!???

thanks


itdaddy
(Starting to like KiXtart)
2007-01-14 12:29 AM
Re: @ERROR giving false positives?

Thahks Glenn
I will try what you suggest! I will do it next week.
thanks a million!

hey i was thinking your pseudo name should be "rocket-man!"hahaah
that would be cool!

thanks
will get back to you here.


Benny69
(MM club member)
2007-01-14 03:26 AM
Re: @ERROR giving false positives?

itdaddy,
Don't piss Jooel off! He knows what he talking about, and i suggest you listen to his suggestions.


Sealeopard
(KiX Master)
2007-01-14 04:22 AM
Re: @ERROR giving false positives?

That code block can be cateogrized as 'horrifying' as it would indicate a lack of understanding of the IF-ELSE-ENDIF construct and functionality. The additional check for @ERROR=0 in the ELSE is superfluous as the only way to actually reach that area is if if 0 to begin with. Thus, the additional check adds absolutely no value. However, if one wants to write absolutely error-free code, then a SELECT-CASE-ENDSELECT would be more appropriate
Code:
SELECT
CASE @ERROR=0
; error is zero
CASE @ERROR<>0
; error is a non-zero value
CASE 1
; error is undefined or otherwise not matching properly
; this should never happen and would be an indicator of a rather catastrophic event
ENDSELECT



NTDOCAdministrator
(KiX Master)
2007-01-14 05:10 AM
Re: @ERROR giving false positives?

Code:
If Not @ERROR
  $RC = RedirectOutPut('success.txt', 0)
  $Element ?
Else
  $RC = RedirectOutPut('failure.txt', 0)  
  $Element ?
Endif


itdaddy
(Starting to like KiXtart)
2007-01-15 05:21 PM
Re: @ERROR giving false positives?

Benny69

Hey Bud, with comments like Jooel's below,
I don't care if your the President of the United States.

Quote:

uhm. but you still keep the double "if" there?
horrifying.


I am new to Kixtart. And I am not an expert programmer like you all.
But I want to get there. Sealeopard did a good thing by explaining
what horrifying meant. I can take slams, but just tell me where I am going wrong or why my code (sucks) isn't ethereal! But code is code sometimes; I have it in many other situations and it works well with NO errors. But I welcome all better code than what I produce that is why this forum is cool!

"Don't kick a baby down when he/she is trying to walk. Just clap for them for just walking even though it is wabbling!" Now noone tear up after I said this! hahahhaha!

Sealeopard,

thanks for the explain on horrifying!

NTDOC thank you as well for you help on my code!


happy new year!

Sealeopard, benny69 and Jooel,

Glenn knows what the traps are for or what I am trying to do.
In my other programs it works well. I am not checking errors twice for the sake of checking errors. I am sending computer names to two separate files.
failures.txt and success.txt. If no errors occur, send screen output which is $Element ? to success.txt and if errors occur, send screen output ($Element ?) or computer name of the action that failed to failure.txt.

So I can have a list of failures and successes for the next days evaluation . It has worked flawlessly in other programs that I have made. But I welcome any better code (I listen to anything you guys say that helps me and I hope I can help you out some day! Thanks guys!









LonkeroAdministrator
(KiX Master Guru)
2007-01-16 06:13 AM
Re: @ERROR giving false positives?

but I told you.
you just failed to listen.

if I got you awake with that comment, good.
but you shouldn't be all offended about that though.


itdaddy
(Starting to like KiXtart)
2007-01-16 10:01 PM
Re: @ERROR giving false positives?

Jooel

did you explain why it was horrifying? i may have missed that?
which post explained why it was crappy code?

My eyes are terrible and sorry if i missed it.
And yes words like horrifying to a newbee are crushing
but I will take your feedback and try to better myself.
thanks a lot bud!

robert(aka itdaddy)

thanks for giving me your thoughts; provoking yes, and got the job done
no hard feelings my bad!!!!!dude! \:\)