[27489] in Kerberos

home help back first fref pref prev next nref lref last post

Re: KfW 3.1: Re-directed stderr of kinit/klist displays dialog

daemon@ATHENA.MIT.EDU (petesea@bigfoot.com)
Thu Feb 22 15:57:43 2007

Date: Thu, 22 Feb 2007 12:56:10 -0800 (Pacific Standard Time)
From: petesea@bigfoot.com
In-reply-to: <6C19D6637F134D4A885DCE3AF06CEC0D@CDCHOME>
To: "Christopher D. Clausen" <cclausen@acm.org>
Message-id: <Pine.WNT.4.64.0702221152030.492@oberon.home.org>
MIME-version: 1.0
Cc: kerberos@mit.edu
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: kerberos-bounces@mit.edu

On Tue, 20 Feb 2007, Christopher D. Clausen wrote:

> Well, can't you check the exit error codes set by the program?
>
> C:\>kinit -kt test
> kinit(v5): Cannot resolve network address for KDC in requested realm
> while getting initial credentials
> C:\>echo %ERRORLEVEL%
> 1

Because that only tells you there was SOME kind of problem.  It doesn't 
tell you what the problem was.

I'm running kinit -kt as a background job ("Scheduled Task").  If it fails 
I'd like to be able to log the reason it failed so I know how to fix it. 
Just knowing that it failed doesn't really help much.

> Also, I can redirect the klist output just fine.  What are you doing?
>
> C:\>klist 2>&1 1>%TEMP%\test.txt
> C:\>cat %TEMP%\test.txt
> Ticket cache: API:notguest@AD.UIUC.EDU
> Default principal: cclausen@AD.UIUC.EDU
> Valid starting     Expires            Service principal
> 02/20/07 18:14:49  02/21/07 04:14:49  krbtgt/AD.UIUC.EDU@AD.UIUC.EDU

stdOUT can be re-directed just fine, it's only stdERR that can't.  Try 
this:

   C:\>klist -c foobar 2>klist.out

where "foobar" is a file that does NOT exist.  This will generate an error 
and since stderr is re-directed to a file, displays a Windows dialog.

Using the exact re-direct syntax you used, causes the behavior to be 
different:

   C:\>klist -c foobar 2>&1 1>klist.out
   klist: No credentials cache found (ticket cache API:foobar)

The error output still doesn't go to the file, but it does go to the 
terminal instead of a Windows dialog.

The reason this happens (and I'm going by the way UNIX redirection works), 
is because "2>&1" says to redirect stderr to the same place as stdout, BUT 
this happens when stdout is associated with the terminal, NOT the file. 
The next part "1>klist.out" says to redirect stdout to a file... but 
stderr is still re-directed to what stdout was BEFORE it was re-directed to 
a file.

The correct (again at least in UNIX) way to redirect both stderr and 
stdout to the same file is this:

   command 1>somefile 2>&1

First you redirect stdout to a file and then you redirect stderr to the 
same place stdout is going... which is now a file.

You can test this concept using any normal dos command that can generate 
both stdout and stderr, eg:

   (you type) C:\>ver 2>&1 1>test.txt
   (you type) C:\>type test.txt
   (displays) Microsoft Windows XP [Version 5.1.2600]

   (you type) C:\>ver /z 2>&1 1>test.txt
   (displays) The syntax of the command is incorrect.
   (NOTE: test.txt is empty)

   (you type) C:\>ver 1>test.out 2>&1
   (you type) C:\>type test.txt
   (displays) Microsoft Windows XP [Version 5.1.2600]

   (you type) C:\>ver /z 1>test.out 2>&1
   (you type) C:\>type test.txt
   (displays) The syntax of the command is incorrect.
________________________________________________
Kerberos mailing list           Kerberos@mit.edu
https://mailman.mit.edu/mailman/listinfo/kerberos

home help back first fref pref prev next nref lref last post