Page 1 of 1 1
Topic Options
#192257 - 2009-02-13 06:15 PM Console - Return 0 Question
aacajo Offline
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
#192260 - 2009-02-13 06:21 PM Re: Console - Return 0 Question [Re: aacajo]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
These are return codes from the function. You can catch them into a variable and they will not display

$nul = writeline(1,"sometest")

There is a really good FAQ on this http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=81941#Post81941
_________________________
Today is the tomorrow you worried about yesterday.

Top
#192262 - 2009-02-13 06:34 PM Re: Console - Return 0 Question [Re: Gargoyle]
aacajo Offline
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
#192264 - 2009-02-13 06:53 PM Re: Console - Return 0 Question [Re: aacajo]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
 Code:
If InGroup("Domain Users")
  If AddPrinterConnection("\\server\printer1")
    "-Printer1 Mapped" ?
  Else
    "-Printer1 not Mapped" ?
  EndIf

  If AddPrinterConnection("\\server\printer2")
    "-Printer2 Mapped" ?
  Else
    "-Printer2 not Mapped" ?
  EndIf
EndIf
_________________________
Today is the tomorrow you worried about yesterday.

Top
#192267 - 2009-02-13 07:27 PM Re: Console - Return 0 Question [Re: Gargoyle]
aacajo Offline
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
#192268 - 2009-02-13 08:19 PM Re: Console - Return 0 Question [Re: aacajo]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Ok then try it this way..

 Code:
If InGroup("Domain Users")
  $rc = AddPrinterConnection("\\server\printer1")
  If $rc = 0
    "-Printer1 Mapped" ?
  Else
    "-Printer1 not Mapped" ?
  EndIf

  $rc = AddPrinterConnection("\\server\printer2")
  If $rc = 0
    "-Printer2 Mapped" ?
  Else
    "-Printer2 not Mapped" ?
  EndIf
EndIf


Edited by Gargoyle (2009-02-13 08:19 PM)
Edit Reason: no code tags
_________________________
Today is the tomorrow you worried about yesterday.

Top
#192269 - 2009-02-13 08:37 PM Re: Console - Return 0 Question [Re: Gargoyle]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
The zeros are coming from further down the script.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#192326 - 2009-02-17 10:27 PM Re: Console - Return 0 Question [Re: Les]
aacajo Offline
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
#192327 - 2009-02-17 10:32 PM Re: Console - Return 0 Question [Re: aacajo]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yes there is.
but I think you should find out where the zeros come from.

easy way to do it?
simply place this line:
 Code:
 ? "done with printers" get $

after the printer section and some other places after that.

this way you will know for sure, what section causes them.
_________________________
!

download KiXnet

Top
#192328 - 2009-02-17 11:15 PM Re: Console - Return 0 Question [Re: Lonkero]
aacajo Offline
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 Administrator Offline
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
 Code:
$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
 Code:
$Rc = Function(arg)
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! \:D

Top
#192346 - 2009-02-18 07:49 PM Re: Console - Return 0 Question [Re: Glenn Barnas]
aacajo Offline
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
Page 1 of 1 1


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

Who's Online
0 registered and 657 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.096 seconds in which 0.073 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