Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #18372 > unrolled thread

trying to redirect both std out and err to a file together and still err to a separate file

Started byqwertmonkey@syberianoutpost.ru
First post2012-08-28 23:59 +0000
Last post2012-08-28 17:10 -0700
Articles 2 — 2 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  trying to redirect both std out and err to a file together and still err to a separate file qwertmonkey@syberianoutpost.ru - 2012-08-28 23:59 +0000
    Re: trying to redirect both std out and err to a file together and still err to a separate file Lew <lewbloch@gmail.com> - 2012-08-28 17:10 -0700

#18372 — trying to redirect both std out and err to a file together and still err to a separate file

Fromqwertmonkey@syberianoutpost.ru
Date2012-08-28 23:59 +0000
Subjecttrying to redirect both std out and err to a file together and still err to a separate file
Message-ID<k1jm16$tn$1@speranza.aioe.org>
 I tested your suggestion with some java code and it works nicely
~ 
 lbrtchx
 comp.unix.shell: trying to redirect both std out and err to a file together
and still err to a separate file  
~ 


import java.util.Locale;
import java.util.Date;
import java.text.DateFormat;
 
// __ 
public class Test{
 public static void main(String[] args){

  DateFormat DF = DateFormat.getDateInstance(DateFormat.FULL, Locale.FRANCE);

// __ std out

  System.out.println("// __ out.println: |" + DF.format(new Date()) + "|");

  DF = DateFormat.getDateInstance(DateFormat.FULL, Locale.CHINESE);

// __ std err

  System.err.println("// __ err.println: |" + DF.format(new Date()) + "|");

// __ Exception in thread "main" java.lang.NullPointerException

  DF = null;

  DF.format(new Date());

 }
}

/*

rm -f *.log

export _DT=`date +%Y%m%d%H%M%S_%s`
echo ${_DT}

(javac Test.java 2>&1 >&3 | tee ${_DT}"_errc.log" >&3) 3> ${_DT}"_errc.log"

(java Test 2>&1 >&3 | tee ${_DT}"_err.log" >&3) 3> ${_DT}"_err_out.log"

ls -l *.log

cat *_err.log

cat *_err_out.log

*/

[toc] | [next] | [standalone]


#18375

FromLew <lewbloch@gmail.com>
Date2012-08-28 17:10 -0700
Message-ID<a28c65e6-2361-4bcd-afb0-79cfa300cbcd@googlegroups.com>
In reply to#18372
(unknown) wrote:
> I tested your suggestion with some java [sic] code and it works nicely

Whose suggestion about what?

>  comp.unix.shell: trying to redirect both std out and err to a file together
> and still err to a separate file  

This is easy to do with shell constructs.

> import java.util.Locale;
> import java.util.Date;
> import java.text.DateFormat;
>  
> // __ 
> 
> public class Test{
> 
>  public static void main(String[] args){
>   DateFormat DF = DateFormat.getDateInstance(DateFormat.FULL, Locale.FRANCE);

http://www.oracle.com/technetwork/java/codeconv-138413.html

You should follow the coding conventions, at least mostly.

> // __ std out

>   System.out.println("// __ out.println: |" + DF.format(new Date()) + "|");

What are you trying to accomplish here?

>   DF = DateFormat.getDateInstance(DateFormat.FULL, Locale.CHINESE);
> 
> // __ std err
> 
>   System.err.println("// __ err.println: |" + DF.format(new Date()) + "|");
> 
> // __ Exception in thread "main" java.lang.NullPointerException
> 
>   DF = null;
>   DF.format(new Date());

What are you trying to accomplish here?

>  }
> }
> 
> /*
> rm -f *.log
> 
> export _DT=`date +%Y%m%d%H%M%S_%s`
> echo ${_DT}
> 
> (javac Test.java 2>&1 >&3 | tee ${_DT}"_errc.log" >&3) 3> ${_DT}"_errc.log"

Your use of quotation marks here is superfluous.

I would have to review this shell command, but it looks weird 
to me. I don't normally go for such outré file-descriptor manipulation 
so it will take time and effort to sort all that stuff out.

> (java Test 2>&1 >&3 | tee ${_DT}"_err.log" >&3) 3> ${_DT}"_err_out.log"
> 
> ls -l *.log
> cat *_err.log
> cat *_err_out.log
> */

Glad it did what you want, though, whatever that was.
Hard to tell when the message is not in its thread context.

-- 
Lew

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web