Running java programs inside a java program -


hi guys want run java programs inside javaprogram.

however when tried execute java command tells me this:

java c:\works\sample stderr: error: not find or load main class c:\works\sample

this code:

private void runbuttonactionperformed(java.awt.event.actionevent evt) {                                                   processor p = new processor();         try {             int k = p.runprocess("javac c:\\works\\sample.java");             if (k == 0) {                        k = p.runprocess("java c:\\works\\sample");             }              system.out.println("value of k: " + k);          } catch (exception e) {             e.printstacktrace();         }     }       

this processor class

public class processor {  public void printlines(string name, inputstream ins) throws exception {     string line = null;     bufferedreader in = new bufferedreader(             new inputstreamreader(ins));     while ((line = in.readline()) != null) {         system.out.println(name + " " + line);     } }  public int runprocess(string command) throws exception {       process pro = runtime.getruntime().exec(command);     printlines(command + " stdout:", pro.getinputstream());     printlines(command + " stderr:", pro.geterrorstream());     pro.waitfor();     // system.out.println(command + " exitvalue() " + pro.exitvalue());     return pro.exitvalue(); } 

}

my files under "c:\works\"

your responses appreciated!

you can having 1 master program run cmd runs whatever processes want , redirect input/output of these processes own input/output happens cmd input/output. here example.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -