-2

I just figured that, we can redirect both System.out and System.err messages to a file, am not able to understand this command which does redirecting while running this below file using : java StandarProgram> output.log 2>error.log

What is 2? and if am not using 2, error messages are displayed on console and not redirected to file? am not able to get this at all.

public class StandardProgram{

    public static void main(String[] args){

       System.out.println("Hello");
       System.err.println("World");

    }
}
Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140
vinay
  • 63
  • 2
  • 10

2 Answers2

3

2 is a standard error file descriptor.

File descriptor 1 is the standard output (stdout). File descriptor 2 is the standard error (stderr).

2>error.log 

is used to redirect the standard error logs to a file named error.log

Pooja Arora
  • 574
  • 7
  • 19
1

System.out is according to documentation Standard Output Stream - it is 1

System.err is according to documentation Standard Error Stream - it is 2

dpassy
  • 363
  • 1
  • 10
  • what are these, exactly 1 & 2? does they help to represent content? – vinay Apr 03 '17 at 09:11
  • those are file descriptors for linux systems 1 means standard output file descriptor 2 means standard error file descriptor – dpassy Apr 03 '17 at 09:11
  • am using windows, is it same with windows? and other OS – vinay Apr 03 '17 at 09:13
  • yes, it is Here is your code snippet in windows cmd: http://stackoverflow.com/questions/1420965/redirect-stdout-and-stderr-to-a-single-file – dpassy Apr 03 '17 at 09:15