PRandal
(Fresh Scripter)
2003-06-03 02:07 PM
Output to Console

This one has come up in these forums a few times.

I've been toying with the idea of using KiXtart as a scripting language for Nagios nrpe_nt. Unfortunately the plugins are required to output to the standard console window (not Ruud's emulation of the same).

At the moment I have to use workarounds like this:

code:
REM cpu.cmd
@echo off
c:\kixtart\kix32 c:\nrpe_nt\cpu.kix
type c:\nrpe_nt\cpu.txt

code:
; cpu.kix

$speed=@MHz
$phys=MemorySize(0)
$sp=""
If $speed <> 0
$sp="$speed"+"MHz "
endif

$out=$sp+"@CPU $phys"+"MB RAM"+@CRLF

$x=redirectoutput("c:\nrpe_nt\cpu.txt",1)
$out

when all I want to do is write to stdout!

Arrrgh!

Ruud, this would be so useful!

We could then do

code:
kix32 stuff.kix > kixout.txt

or better still
code:
kix32 stuff.kix | fancyprogram.exe

Please please please give us a simple and effective way of writing to the real CON from KiXtart.

Thanks in advance (but not holding my breath)

Phil

[ 03. June 2003, 14:10: Message edited by: PRandal ]


Richard H.Administrator
(KiX Supporter)
2003-06-03 03:00 PM
Re: Output to Console

The good news is than you can do this. Hurrah.

Add these two lines at the start of your script:
code:
$=SetOption("ASCII","ON")
$=SetOption("WrapAtEOL","ON")

Now, you can pipe the output:
code:
kix32.exe myscript.kix | more

Or even redirect it to the console:
code:
kix32.exe myscript.kix >CON:

You will notice that outputting directly to the console is not particularly useful as control characters do not get handled.


PRandal
(Fresh Scripter)
2003-06-03 03:06 PM
Re: Output to Console

Thanks, that works perfectly.

Phil


LonkeroAdministrator
(KiX Master Guru)
2003-06-03 04:06 PM
Re: Output to Console

w0w!
what those 2 lines have to do with the piping itself?

as far as I see it, they are just formatting commands, no?


Richard H.Administrator
(KiX Supporter)
2003-06-03 05:19 PM
Re: Output to Console

It was Phils comment about the console being "Ruud's emulation" that sent me down this path.

  • KiXtart truncates output to the console if it would wrap - wholly inappropriate for piped or redirected data so you want to switch that off.
  • Standard output is in Unicode, which again is not usefull when piping or redirecting output, as you will get two bytes for each character and no application that you are piping to is likely to understand that. Switching to ASCII fixes that problem.
You could probably get away with just switching to ASCII, but I'd recommend both.


ShawnAdministrator
(KiX Supporter)
2003-06-03 05:44 PM
Re: Output to Console

very nice, very, very nice. this should be documented and highlited seperately in the kixtart manual.

NTDOCAdministrator
(KiX Master)
2003-06-03 07:30 PM
Re: Output to Console

Or at least in the FAQ here on the board.

Kent, Les Can one of you guys look at adding this to either one of the other FAQs or one of its own.

Thanks.


Les
(KiX Master)
2003-06-03 07:31 PM
Re: Output to Console

DOC,
It was your idea... you do it! [Big Grin]


LonkeroAdministrator
(KiX Master Guru)
2003-06-03 07:43 PM
Re: Output to Console

uhm, from the very first initial post I understood that piping is not possible. [Confused]

phil, why are you and other guys confusing me! [Frown]


MCA
(KiX Supporter)
2003-09-07 02:23 AM
Re: Output to Console

Dear,

Great information, which can't be find on the FAQ forum now.

Good suggestion to put it there too. A manual people aren't reading all the time.
For newbies the amount of new information is too much. For oldies they think
"the manual doesn't contain new information for me".
greetings.

(TIP_how_to_redirect_kix32_output)


LonkeroAdministrator
(KiX Master Guru)
2003-09-08 12:16 AM
Re: Output to Console

now, the documentation about this should also make clear that this only works with the old console version of kix.