【发布时间】:2023-03-06 01:33:01
【问题描述】:
有没有办法在 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();
}
}
【问题讨论】:
-
你说的是终端(unix),还有bat文件(Windows),你的目标是什么操作系统?
-
Windows,误用“终端”一词。请替换为“提示”。
-
这里的问题很难诊断。请提供 MVCE。至于 .bat 的编写,我非常怀疑 Java 是否支持编写批处理文件,因为它们是特定于平台的。
-
.bat文件可以只是具有该扩展名的文本文件,因此 Java 可以处理这些。 -
Java 可以编写 .bat 文件,因为它们只是带有 bat 扩展名的文本文件。