Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

IO from java and javac  RSS feed

 
Gregory Guy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone help?
I have a very simple editor written in Java that has a compile and exceute button on a GUI.
How does one trap the error messages generated by javac.exe and java.exe?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gregory,

Welcome to JavaRanch!

If you're using Runtime.exec() to execute these things, you'll get a Process object as a result. That Process object has getInputStream, getOutputStream, and getErrStream methods. getInputStream returns a pipe connected to the process's standard output, and getErrStream give you the standard error output. Compiler errors will show up on the error stream; regular output from most programs will show up on the output stream. What you need to do is read, in a loop, everything that comes from these streams, and then presumably display it somewhere. Often people use threads to do this -- one for normal output, one for error output.
 
Gregory Guy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to Ernest.
All sorted out.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!