#192257 - 2009-02-13 06:15 PM
Console - Return 0 Question
|
aacajo
Fresh Scripter
Registered: 2009-02-13
Posts: 34
Loc: Canada
|
I have read an article on here under the FAQ section of the forum however I could not make sense of it. I'm pretty new to KIX and I am trying to figure out how to stop KIX from returning 0's to the command line screen.
This happens when I map printers and write to the registry. Anyone have a simple way to prevent this?
Thanks in advance!
|
|
Top
|
|
|
|
#192262 - 2009-02-13 06:34 PM
Re: Console - Return 0 Question
[Re: Gargoyle]
|
aacajo
Fresh Scripter
Registered: 2009-02-13
Posts: 34
Loc: Canada
|
Thank you for the prompt reply! I'm trying to relate the example code to the code I currently have and I don't see how to apply it.
The output of the following is:
-Printer1 added successfully -Printer2 added successfully00
Here is what i have:
; \\ Printer Additions for Domain Users
IF INGROUP("Domain Users") = 1 ADDPRINTERCONNECTION ("\\server\printer1") ADDPRINTERCONNECTION ("\\server\printer2")
Sleep 5 ENDIF
; \\ Error or success return
IF ADDPRINTERCONNECTION ("\\server\printer1") = 0 ?" -Printer1 Mapped Successfully" ENDIF
IF ADDPRINTERCONNECTION ("\\server\printer1") = 1 ?" -Printer1 was unable to map" ENDIF
IF ADDPRINTERCONNECTION ("\\server\printer2") = 0 ?" -Printer2 Mapped Successfully" ENDIF
IF ADDPRINTERCONNECTION ("\\server\printer2") = 1 ?" -Printer2 was unable to install" ENDIF
|
|
Top
|
|
|
|
#192267 - 2009-02-13 07:27 PM
Re: Console - Return 0 Question
[Re: Gargoyle]
|
aacajo
Fresh Scripter
Registered: 2009-02-13
Posts: 34
Loc: Canada
|
Still getting the 0's returned after the AddPrinterConnection command. Thanks again for your help.
|
|
Top
|
|
|
|
#192326 - 2009-02-17 10:27 PM
Re: Console - Return 0 Question
[Re: Les]
|
aacajo
Fresh Scripter
Registered: 2009-02-13
Posts: 34
Loc: Canada
|
I've commented out the rest of the script to make sure and I am still getting the zero's returned. However when I am mapping drives above the printers section of the script it is not returning zeros on success. I changed up my code to use "SELECT" to map printers based on subnet in hopes of the zeros going away however no dice.
There is no universal code to type at the beginning of the script to hide the zero's from displaying on the console? I suppose that is a dumb question but just wondering.
Thanks again to both of you for the help.
|
|
Top
|
|
|
|
#192328 - 2009-02-17 11:15 PM
Re: Console - Return 0 Question
[Re: Lonkero]
|
aacajo
Fresh Scripter
Registered: 2009-02-13
Posts: 34
Loc: Canada
|
This just pauses my script. Should I be looking for something specific?
Zero's only return after ? " Printer mapped successfully" on the console window.
|
|
Top
|
|
|
|
#192329 - 2009-02-18 01:01 AM
Re: Console - Return 0 Question
[Re: aacajo]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
|
Do you undertand why it's happening? I'm guessing not, otherwise your questions might be a bit different..
Some "programming 101" -
There are two basic classes of program operation, a Command and a Function. In the most simple form, a command simply does something - with or without an argument - but doesn't return any information. Often, it won't even return a success/fail result.
Functions, on the other hand, can return two types of information - a Return Value and an Exit Status. The "Exit Status" indicates the "quality" of the function's performance - did it succeed (exit 0) or fail (exit ERROR_CODE). This can be checked in Kix via the @ERROR macro, which contains the function's exit code, and @SERROR, which contains the text representation of the error code.
The "Return Value" is what you are seeing on the screen. Many Kix functions mirror the Exit Status in the Return Value, so the "0" being returned indicates that the function was successful. Thus, most functions should be used with the form $ReturnCode = Function(arg) Often, the return code is not really needed, but you don't want to "litter" and just drop the value on the console screen floor, so you will see something like fairly often, with no further reference to the $Rc value. This format simply "catches" the Return Value, kind of like a programmatic trash can. 
Scan your code. Every time you see a function(), see if there's a variable to catch the return value. If there isn't, use $Rc (commonly used to ignore a Return Code) to catch the return code and see if your litter gets cleaned up.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#192346 - 2009-02-18 07:49 PM
Re: Console - Return 0 Question
[Re: Glenn Barnas]
|
aacajo
Fresh Scripter
Registered: 2009-02-13
Posts: 34
Loc: Canada
|
Very informative. That worked great.
I guess in my mind $Rc = Function(arg) would be setting the value $Rc to the function to be used later on. I've always went in with the mentality that you declare your variables first then go in head first.
This post helped me a lot. Thanks again to everyone for the prompt replies!
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 657 anonymous users online.
|
|
|