Executing java application on Unix.
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   ruben_maroscia
Posted On:   Monday, November 3, 2003 05:04 AM

How can I to execute a java application on Unix? Here's my code: import java.io.*; class CompEsegui{ public static void main(String[] args){ System.out.println( "Compiling..." ); Runtime env1 = Runtime.getRuntime(); try { Process proc1 = env1.exec( "javac -d Compiled Prova0.java" ); try { proc1.waitFor(); } catch (InterruptedException i) { } InputStream s1 = proc1.getErrorStream(); System.out.println(""); BufferedInputStream bis1 = new BufferedInputStream(s1); for (int k=0; k <24*bis1.available(); k++) { System.out.print( (char) bis1.read() ); } } catch (IOException e)    More>>

How can I to execute a java application on Unix?

Here's my code:


import java.io.*;


class CompEsegui{
public static void main(String[] args){
System.out.println( "Compiling..." );
Runtime env1 = Runtime.getRuntime();
try { Process proc1 = env1.exec( "javac -d Compiled Prova0.java" );
try { proc1.waitFor();
} catch (InterruptedException i) {
}
InputStream s1 = proc1.getErrorStream();
System.out.println("");
BufferedInputStream bis1 = new BufferedInputStream(s1);
for (int k=0; k <24*bis1.available(); k++) {
System.out.print( (char) bis1.read() );
}
} catch (IOException e)
{System.out.println( "IO exception: " + e);
}

/***************FileExecution******************/

Runtime env2 = Runtime.getRuntime();
System.out.println("executing...");
try { Process proc2 = env2.exec( "java /Compiled/Prova0" );
try { proc2.waitFor();
} catch (InterruptedException i) {
}
InputStream s2 = proc2.getInputStream();
BufferedInputStream bis2 = new BufferedInputStream(s2);
for (int k=0; k <128*bis2.available(); k++) {
System.out.print( (char) bis2.read() );
}
} catch (IOException e)
{System.out.println( "IO exception: " + e);
}
/*********************************************/
System.out.println (""); System.out.println( "bye." );
}
}

The file is compiled into Compiled directory, but how can I execute the command java Compiled/Prova0 in an other directory (for example OutDirectory)?

It's possible?

Thanx

   <<Less
About | Sitemap | Contact