Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

javac produces many error messages, how do I capture these error messages in a file?  RSS feed

 
raymond hsu
Greenhorn
Posts: 23
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, this is my second question posted in a day.

When I use javac to compile a java program,
it produces many error messages scrolling too fast in the 24 line command window.

Is there a way to redirect the output errors to a file,
or that I can direct the javac to pause afer every 23 lines of error message displayed ?

Thanks again
 
Henry Wong
author
Sheriff
Posts: 23284
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my opinion, it is probably better to let the Operating System do that for you. You can simply redirect standard out (and standard err) to a file. Or you can even redirect them via a pipe to program like "more" that will pause the output for you.

Of course, to do this, it would help if we knew which OS you are using.

Henry
 
Dave Tolls
Rancher
Posts: 2914
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can make the command window bigger.
If this is windows then open the properties for the cmd (the little black box in the top left, and select Properties) and change the screen buffer size in the layout tab.

You could also do:
javac <your file> > errors.txt
which will stick the output in an 'errors.txt' file.

If you're getting that many compilation issues, though, then you've probably written too much code before compiling.
 
raymond hsu
Greenhorn
Posts: 23
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Henry for your reply.

I am using Java 6 on Window XP.

Command Window is DOS.

I tried using

javac javaprog > errf
javac javaprog >> errf
javac javaprog | more

all don't work, errf is 0 byte, and screen don't pause
 
Henry Wong
author
Sheriff
Posts: 23284
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
raymond hsu wrote:
I tried using

javac javaprog > errf
javac javaprog >> errf
javac javaprog | more

all don't work, errf is 0 byte, and screen don't pause


Try...

javac javaprog > errf 2>&1

Henry
 
raymond hsu
Greenhorn
Posts: 23
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry, thank you very much, it works now.
errf is not 0 bytes.

Care to explain what is 2 > &1 ?
 
Liutauras Vilda
Marshal
Posts: 4670
320
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
raymond hsu wrote:Henry, thank you very much, it works now.
errf is not 0 bytes.

Care to explain what is 2 > &1 ?

Have you tried google it? What have you found?

I tried, my results here.
I managed to find an answer in top 2 linked websites. Give a try and please tell us if you managed too.
 
raymond hsu
Greenhorn
Posts: 23
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Liutauras Vilda ,

I did google, and what I have understood (actually not very clearly) is

>& Writes the output from one handle to the input of another handle.
hence 2>&1 (with no space in between) will redirect 2(std error) to 1(std output)

> errf 2>&1 will first redirect stdout to errf file, and redirect std error to std output (which is now rediected to errf)

because javac write error messages to stderr and not stdout, that is why when I use
javac javaprog > errf
I got nothing in errf file.

And when I type

javac javeprog 2>&1 > errf

it wont work, because stderr is redirected to stdout, but stdout has not yet been redirected to errf, hence stderr still output to screen because stdout is to screen, then stdout is redirected to errf, but since javac write error message to only stderr, so, errf is still 0 byte.

I hope my understanding is correct

 
Knute Snortum
Sheriff
Posts: 4091
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That looks correct to me.
 
Liutauras Vilda
Marshal
Posts: 4670
320
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
raymond,

I gave you a cow for looking and finding answer to your own question You'll need to use that technique a lot, so that cow can be an extra stimulus to research problem a lot on your own first.
That doesn't mean you cannot ask questions, don't misinterpret me. That only means, that spending time on looking for a certain information on your own first, gives an ability to find other closely related to topic important information which you might were not aware of.

This is what I do, when I don't know (that happens everyday) I look in my books first, then search on Internet.
 
Henry Wong
author
Sheriff
Posts: 23284
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my favorite part of the explanation...

raymond hsu wrote:
And when I type

javac javeprog 2>&1 > errf

it wont work, because stderr is redirected to stdout, but stdout has not yet been redirected to errf, hence stderr still output to screen because stdout is to screen, then stdout is redirected to errf, but since javac write error message to only stderr, so, errf is still 0 byte.


I believe most beginners get this wrong, as they believe that "2>&1" will merge those two streams, and hence, should be done first. But as Raymond correctly noted, what it does is assign the stderr to the current value of the stdout, which of course, hasn't been redirected yet. Good job !!

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!