gpt4 book ai didi

java - 使用java在终端中运行多个命令?

转载 作者:行者123 更新时间:2023-11-30 11:10:01 24 4
gpt4 key购买 nike

有没有办法在 Java 中编写和运行 .bat 文件然后删除它们,或者在不使用批处理文件的情况下在 java 中这样做,我需要每个客户端自己加载提示实例。

这是我的加载器类

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();
}
}

最佳答案

由于 .bat 文件只是文本文件,您可以使用 FileOutputStream 来创建它们。然后我会查看 Runtime.getRuntime().exec("");ProcessBuilder 来执行它们,然后在完成后删除文件。

另见

Runtime
ProcessBuilder

关于java - 使用java在终端中运行多个命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27909203/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com