2019-08-16

Sequence of 2>&1 in sh start script cause exceptions were not log into file, but show on screen.



Content of Hello.java


public class Hello
{
    public static void main(String[] args) throws Exception
    {
        System.out.println("Hello");
        throw new Exception("world");
    }
}






-------------------------------------------------------------------------------------------------------



[billson@virtual-jenkins Documents]$ javac Hello.java; java -cp . Hello 2>&1 > null.txt
Exception in thread "main" java.lang.Exception: world
    at Hello.main(Hello.java:8)


[billson@virtual-jenkins Documents]$ cat null.txt
Hello





-------------------------------------------------------------------------------------------------------

[billson@virtual-jenkins Documents]$ javac Hello.java; java -cp . Hello > null 2>&1


[billson@virtual-jenkins Documents]$ cat null.txt
Hello
Exception in thread "main" java.lang.Exception: world
    at Hello.main(Hello.java:8)








No comments:

Google Referrals