在终端中使用 java 到 运行 多个命令?
Using java to run multiple commands in terminal?
有没有办法在 Java 中写入和 运行 .bat
文件,然后删除它们,或者在 java 中这样做而不使用批处理文件,我需要每个客户端都加载到它自己的提示实例上。
这是我的装载机 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();
}
}
由于 .bat
文件只是文本文件,您可以使用 FileOutputStream
来创建它们。然后我会查看 Runtime.getRuntime().exec("");
或 ProcessBuilder
来执行它们,然后在完成后删除文件。
另请参阅
有没有办法在 Java 中写入和 运行 .bat
文件,然后删除它们,或者在 java 中这样做而不使用批处理文件,我需要每个客户端都加载到它自己的提示实例上。
这是我的装载机 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();
}
}
由于 .bat
文件只是文本文件,您可以使用 FileOutputStream
来创建它们。然后我会查看 Runtime.getRuntime().exec("");
或 ProcessBuilder
来执行它们,然后在完成后删除文件。
另请参阅