• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to direct compile-error message to a txt file?

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a question about command line usage rather than Java code.

I'm trying to direct compile-error message to a txt file using this command: javac *.java >result.txt. But it seems only messages delivered by Java statement System.out.XXX could be put into target txt file. For error messages delivered by System.err.XXX, it could only be displayed on the screen, and cannot be put into txt file.

Is there a command or argument I could use to direct compile time err msg into a txt file?

Thanks.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
System.out.XXX & System.err.XXX will only output something when your program is running, not when it is compiling.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think it's going to depend on the OS, but on Windos, i think you can do

javac *.java 2 > result.txt

what i THINK i'm remembering is that the 2 means the stderror messages. so you could do

javac *.java > result.txt 2 > erorr.txt

to separate error messages from the 'everything is ok' messages. but don't hold me to this... it's been a while since i've had to do that...
 
Nancy Zhang
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great thanks, fred rosenberger, it works! The only thing needs attention is that there is no whitespace between 2 and >, otherwise, java command argument error.
Thanks again!
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ah... sorry about that. but i'm glad you figured it out!!!
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to direct everything to one file rather than two, this should work on both Unix and Windows:

javac *.java 1>result.txt 2>&1
 
Nancy Zhang
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah! this one is cool! will use it. Thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic