How to start an external program inside a java program -


this question has answer here:

i new in how start program inside java program! , don't know how call it. 1st question must inside new thread? second question how call new program. program want call "wondershaper". use ubuntu 12.04 running programm , in command line write. "sudo wondershaper eth0 10000 1000". how can write inside general program? have server want handle rate of it! thats why use it. have multithread server , code

class client extends thread {     private socket connectionsocket;       public client(socket c) throws ioexception {         connectionsocket = c;     }      public void run() {          string path = "c:/pao/new2/";          file folder = new file(path);         file[] listoffiles = folder.listfiles();           try {              string filetosendstr = readfile();             file filetosend = null;             (file f : listoffiles)              {                                if (f.getname().equals(filetosendstr)) {                     filetosend = f;                     break;                 }             }             //system.out.println("connescting client recieve part " +filetosendstr);             if (filetosend == null) {              }             system.out.println("sending chunk client " + filetosendstr + "to client: " +connectionsocket.getremotesocketaddress().tostring());             java.util.date date= new java.util.date();              system.out.println(new timestamp(date.gettime()));             long length = filetosend.length();             byte [] longbytes = new byte[8];             bytebuffer bbuffer = bytebuffer.wrap(longbytes);             bbuffer.putlong(length);             connectionsocket.getoutputstream().write(longbytes);              bufferedoutputstream bout = new bufferedoutputstream(connectionsocket.getoutputstream());             bufferedinputstream bain = new bufferedinputstream(new fileinputstream(filetosend));              byte buffer [] = new byte [1024];             int = 0;             while((i = bain.read(buffer, 0, 1024)) >= 0){                  bout.write(buffer, 0, i);               }                system.out.println("chunk sended");             java.util.date date1= new java.util.date();              system.out.println(new timestamp(date1.gettime()));             bout.close();             bain.close();           } catch (ioexception e) {             e.printstacktrace();         }      }      private string readfile() throws ioexception {          bufferedreader r = new bufferedreader(new inputstreamreader(                 connectionsocket.getinputstream()));         return r.readline();      } } 

so when read readfile client send me. after if rate string start "wondershaper" , put rate inside "sudo wondershaper eth0 10000 rate" , start program

process aprocess = runtime.getruntime().exec("cmd"); //you can pass process here

you can read output of program.

inputstream = aprocess.getinputstream(); 

ps: can pass process, along arguments, can't pass things >>, 2> or | or wild cards *

-- comments


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -