Adds working test code for writing and reading console
This commit is contained in:
parent
b9963c3a89
commit
83f012cf7f
@ -29,7 +29,7 @@ public class Server {
|
||||
private ServerType type;
|
||||
private String serverVersion;
|
||||
private String maxRam;
|
||||
private long pid;
|
||||
private Process process;
|
||||
|
||||
public Server(String name) {
|
||||
this.name = name;
|
||||
@ -39,7 +39,7 @@ public class Server {
|
||||
this.type = null;
|
||||
this.serverVersion = null;
|
||||
this.maxRam = ramList[0];
|
||||
this.pid = -1;
|
||||
this.process = null;
|
||||
servers.add(this);
|
||||
}
|
||||
|
||||
@ -64,6 +64,10 @@ public class Server {
|
||||
return servers;
|
||||
}
|
||||
|
||||
public Process getProcess() {
|
||||
return this.process;
|
||||
}
|
||||
|
||||
public void toggle() {
|
||||
this.enabled = !this.enabled;
|
||||
}
|
||||
@ -120,11 +124,13 @@ public class Server {
|
||||
System.out.println("File was not found.");
|
||||
return;
|
||||
}
|
||||
Runtime rt = Runtime.getRuntime();
|
||||
//Runtime rt = Runtime.getRuntime();
|
||||
try {
|
||||
System.out.println("Executing command.");
|
||||
Process pr = rt.exec("\"java\" -Xmx" + this.maxRam + " -Xms512M -jar " + "\"" + this.path + "\\" + this.type + "\" nogui", null, new File(this.path));
|
||||
this.pid = pr.pid();
|
||||
ProcessBuilder builder = new ProcessBuilder("java", "-Xmx" + this.maxRam, "-Xms512M", "-Djline.terminal=jline.UnsupportedTerminal", "-Dcom.mojang.eula.agree=true", "-jar", "\"" + this.path + "\\" + this.getType() + "\"");
|
||||
builder.directory(new File(this.path));
|
||||
builder.redirectErrorStream(true);
|
||||
Process pr = builder.start();
|
||||
this.process = pr;
|
||||
System.out.println("Success");
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error");
|
||||
|
@ -1,7 +1,8 @@
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import net.knarcraft.serverlauncher.server.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* A class for testing new and existing features.
|
||||
@ -11,7 +12,7 @@ import java.util.ArrayList;
|
||||
* @since 0.0.0.1
|
||||
*/
|
||||
public class ServerTest {
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws IOException {
|
||||
try {
|
||||
ServerType.loadServerTypes();
|
||||
} catch (ConfigurationException e) {
|
||||
@ -22,9 +23,23 @@ public class ServerTest {
|
||||
Server server1 = Server.getServers().get(0);
|
||||
server1.toggle();
|
||||
server1.setPath("C:\\Users\\Kristian\\Desktop\\Test");
|
||||
server1.setType(ServerType.getServerTypes().get(6));
|
||||
server1.setServerVersion("1.6.4");
|
||||
server1.setType(ServerType.getServerTypes().get(4));
|
||||
server1.setServerVersion("1.12.2");
|
||||
server1.setMaxRam("1G");
|
||||
Server.startServers();
|
||||
|
||||
OutputStream stdin = server1.getProcess().getOutputStream ();
|
||||
InputStream stdout = server1.getProcess().getInputStream ();
|
||||
|
||||
BufferedReader reader = new BufferedReader (new InputStreamReader(stdout));
|
||||
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin));
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine ()) != null) {
|
||||
System.out.println ("Stdout: " + line);
|
||||
writer.write("stop\n");
|
||||
writer.flush();
|
||||
}
|
||||
//writer.close();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user