File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes 2>&1 redirection Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "2>&1 redirection" Watch "2>&1 redirection" New topic
Author

2>&1 redirection

rahul dighe
Ranch Hand

Joined: Apr 17, 2001
Posts: 44
Hi,
I have seen the use of 2>&1 to seperate redirection of System.err and System.out. Can someone please explain me how I can achieve the following on Windows NT and UNIX
I have a programme which has two statements, one is System.out, and other System.err
i want the System.err redirected to a file and system.out to continue on the console ..
can someone tell me how do i invoke the command line for e.g.
java Test 2> out.txt ?? etc.. ?
also what does '2' '&' '1' mean ???


<BR>Rahul Dighe
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1863
hi Rahul,
so what you are trying to do? i'm not clear i think.
u seem to already know how to redirect the stderr to the file. then what is the question?
do u want something similar on Win NT?
as far as 2,& and 1 description is concerned,
In unix
0 = Standard input file descriptor (stdin)
1 = Standard output file descriptor (stdout)
2 = Standard error file descriptor (stderr)
when you say 2>&1 it means that stderr should be redirected to stdout. ie. all System.err.println() output gets print on Stdout.
also this might be helpful...
regards
maulin.


1. Have fun @ http://faq.javaranch.com/java/JavaRaq
2. Looking for simple infix2postfix conversion and postfix evaluation package? Click here
rahul dighe
Ranch Hand

Joined: Apr 17, 2001
Posts: 44
thanks i got my answer
i have seen the 2&1 being used for redirection, but i did not know the logic behind it, the about.com link is very useful.
 
IntelliJ Java IDE
 
subject: 2>&1 redirection
 
Threads others viewed
exception
System.out and System.err
System class and available methods
exception
redirect conosle result
IntelliJ Java IDE