diff --git a/src/net/knarcraft/serverlauncher/server/Server.java b/src/net/knarcraft/serverlauncher/server/Server.java index 018239f..8bb86fd 100644 --- a/src/net/knarcraft/serverlauncher/server/Server.java +++ b/src/net/knarcraft/serverlauncher/server/Server.java @@ -127,6 +127,7 @@ public class Server { throw new FileNotFoundException("Version file could not be downloaded."); } newestVersion = stringBetween(versionText, type.getSrcStart(), type.getSrcEnd()); + System.out.println(newestVersion); success = downloadFile(type.getDownloadURL() + newestVersion + type.getDownloadURLPart() + newestVersion + ".jar", filePath); //TODO: Register the new version number, and only download if version mismatch or missing file. if (!success) { @@ -208,6 +209,7 @@ public class Server { * @return The wanted substring. */ private String stringBetween(String string, String start, String end) { - return string.substring(string.indexOf(start) + 1 + start.length(), string.indexOf(end)); + int startPos = string.indexOf(start) + start.length(); + return string.substring(startPos, string.indexOf(end, startPos)); } } \ No newline at end of file diff --git a/test/ServerTest.java b/test/ServerTest.java index a557cd5..c77ae75 100644 --- a/test/ServerTest.java +++ b/test/ServerTest.java @@ -1,7 +1,6 @@ import net.knarcraft.serverlauncher.server.*; -import java.io.FileNotFoundException; -import java.io.IOException; +import java.io.*; import java.util.ArrayList; public class ServerTest { @@ -44,17 +43,24 @@ public class ServerTest { if (server.isEnabled()) { String path = server.getPath(); String type = server.getType(); - try { + /* try { server.downloadJar(); System.out.println("File downloaded."); } catch (FileNotFoundException e) { System.out.println("File was not found."); return; - } + }*/ String ram = server.maxRam(); Runtime rt = Runtime.getRuntime(); try { - Process pr = rt.exec("java -Xmx" + ram + " -Xms512M -jar " + "\"" + path + "\\" + type + "\" nogui"); + Process pr = rt.exec("java -Xmx" + ram + " -Xms512M -jar " + "\"" + path + "\\" + type + "\"", null, new File(server.getPath())); + String line; + BufferedReader in = new BufferedReader( + new InputStreamReader(pr.getInputStream()) ); + while ((line = in.readLine()) != null) { + System.out.println(line); + } + in.close(); long pid = pr.pid(); server.updatePid(pid); System.out.println("Success");