2

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();
    }
}
5
  • You're talking about terminal (unix) but also about bat files (Windows), what OS are you targeting? Commented Jan 12, 2015 at 19:22
  • Windows, misuse of the word "terminal". Please replace with "prompt". Commented Jan 12, 2015 at 19:23
  • It's difficult to diagnose the problem here. Please provide a MVCE. As for the .bat writing, I highly doubt Java provides support for writing batch files, as they are platform specific. Commented Jan 12, 2015 at 19:31
  • .bat files can just be text files with that extension, so Java can handle those. Commented Jan 12, 2015 at 19:36
  • Java can write .bat files since they are just text files with a bat extension. Commented Jan 12, 2015 at 19:38

1 Answer 1

1

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

Runtime
ProcessBuilder

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for being able to understand my problem! Got everything working fine! Once again thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.