• 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

Running Batch Files

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.. ?
 
"I know this defies the law of gravity... but I never studied law." -B. Bunny Defiant tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic