Reputation: 187
Is there a way to write and run .bat
files in Java then delete them after, or doing so in java without the use of batch files, I need each client to be loaded on its own instance of prompt.
Here's my loader class
public class TBotLoader implements Runnable {
private Thread t;
private String name;
private String password;
private int script;
private String acc;
private String proxy;
private int world;
public TBotLoader(String name, String password, int script, String acc, String proxy, int world){
this.name = name;
this.password = password;
this.script = script;
this.acc = acc;
this.proxy = proxy;
this.world = world;
System.out.println("Creating Thread: " + acc);
}
@Override
public void run() {
final String home = System.getProperty("user.home");
try {
Runtime.getRuntime().exec("java -jar " + home + "/Documents/proj/jar.jar" + " -s " + this.script + " -a " + this.acc + " -n " + this.name + " -pw " + this.password + " -w " + this.world + " -proxy " + this.proxy);
Thread.sleep(50);
} catch (Exception e) {
System.out.println("Failed to spawn clients");
System.out.println(e.getMessage());
}
}
public void start() {
System.out.println("Starting thread: " + this.acc);
t = new Thread(this, acc);
t.start();
}
}
Upvotes: 2
Views: 762
Reputation: 15174
Since .bat
files are just text files, you can use a FileOutputStream
to create them. I would then look into Runtime.getRuntime().exec("");
or ProcessBuilder
to execute them and then just delete the file when done.
See Also
Upvotes: 1