0

Got a bit of an issue that I can't seem to find online..

Basically I'm writing a java program that is essentially a GUI to start stop minecraft server instances. Sounds OTT but it's fun so whatever.

I've ran into an issue whereby I could not get java to run a batch file, so I converted it to exe to make it easier. The exe runs fine if you double click it, it runs fine if you call it from cmd but when testing (I'm coding in Eclipse) just.. nothing happens.

        
        String fileLocation = serverList.get("Survival Mode");
        Process p = Runtime.getRuntime().exec(fileLocation);

The file location in this instance is D:\Public\Minecraft Servers\Survival Mode\survivalmode.exe

All the exe/batch file does is as follows:

D:
cd "D:\Public\Minecraft Servers\Survival Mode"
java -Xmx1024M -Xms1024M -jar server.jar nogui
pause

EDIT:

Then for testing I used ProcessBuilder, I did something super simple and coded this:

private static void testRun() throws IOException {

           ProcessBuilder processBuilder = new ProcessBuilder();
           processBuilder.command("cmd.exe", "/c", "dir C:\\");
           Process process = processBuilder.start();

And again, nothing happens!!

Any ideas what I'm doing wrong? In eclipse even ran as administrator - nothing happens. It does not print a stack trace, no errors in the process, just.. nothing :(

TIA

murphy575
  • 13
  • 3
  • **1.** `ProcessBuilder` was introduced to handle the error prone I/O. **2.** Use `cmd.exe` with parameters for .bat. **3.** You might not need a .bat, setting the working directory: https://stackoverflow.com/questions/840190/changing-the-current-working-directory-in-java and java.exe. – Joop Eggen Apr 19 '21 at 06:19
  • Err, when it is an exe file, that would mean it is a binary executable? But then you provided the content of a batch script? If it is really a batch script then make the file ending.bat and do as Joop says. – GhostCat Apr 20 '21 at 20:40

0 Answers0