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

Running Batch Files  RSS feed

 
Dave Donohoe
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi all,
I have a small App that reads in a Java Source File, I want my app to run a batch file to compile the Source. (File contains 'javac myclass.java'.
After this has run, I want to read in the output from the compilation (ie warnings, errors etc). My code executes the batch file correctly, but when I try to read in the output, all thats read in is the command from the batch file (ie javac myclass.java)
Here is the code that executes the batch file (command) & uses InputStream to read in the data at the command prompt.

try
{
Process child = Runtime.getRuntime().exec(command);
Runtime.getRuntime().wait();
InputStream in = child.getInputStream();
int c;
String szOutText = new String("");

while ((c = in.read()) != -1)
{
char cText = ((char)c);
String szStr = String.valueOf(cText);
szOutText = szOutText + szStr;
}
System.out.println(szOutText);
textOut.setText(szOutText);
in.close();
} catch(IOException e)
I tried changing the batch file from javac myclass.java to javac myclass.java << output.txt but this just creates the empty text file & the errors are still displayed on screen,
What am I doing wrong? or can this be done at all?
Thanks.
Dave
 
Tom Breuer
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
problem sounds similar to mine, i have 3 files in the directory, file1, file2 and new.txt i need to delete files 1/2 and then rename new.txt file1.txt, should i try to run a batch file to carry out the task or what? runtime.. ?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!