Solved ProcessBuilder Help

Discussion in 'Spigot Plugin Development' started by Swedz, Jun 26, 2016.

  1. To run my Hub server, I am using a shell script that is in /root/minecraft/Hub/, and this runs the hub server, and to run that I use cd minecraft/Hub (didn't include /root/ because I'm using the root user), and that runs fine. But in a plugin I've been working on, I'm trying to get it to boot up a specific server at a specific location. I've managed to get a ProcessBuilder (sort of) setup:
    Code (Text):
    File working_dir = new File("/root/minecraft/PlayerServers/" + server + "/");
    if(working_dir.exists()) {
        ProcessBuilder pb = new ProcessBuilder("sh /root/minecraft/PlayerServers/" + server + "/");;
    And this runs fine, but I get a "No such file or directory" error in console:
    Code (Text):
    [13:53:13] [Server thread/WARN]: Cannot run program "sh /root/minecraft/PlayerServers/PS-1/" (in directory "/root/minecraft/PlayerServers/PS-1"): error=2, No such file or directory
    [13:53:13] [Server thread/WARN]:     at java.lang.ProcessBuilder.start(
    [13:53:13] [Server thread/WARN]:     at me.Swedz.core.api.PlayerServerAPI.bootup(
    [13:53:13] [Server thread/WARN]:     at me.Swedz.core.api.PlayerServerAPI.startup(
    [13:53:13] [Server thread/WARN]:     at me.Swedz.core.api.PlayerServerAPI.create(
    [13:53:13] [Server thread/WARN]:     at me.Swedz.lobby.Lobby.onInventoryClick(
    [13:53:13] [Server thread/WARN]:     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [13:53:13] [Server thread/WARN]:     at sun.reflect.NativeMethodAccessorImpl.invoke(
    [13:53:13] [Server thread/WARN]:     at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    [13:53:13] [Server thread/WARN]:     at java.lang.reflect.Method.invoke(
    [13:53:13] [Server thread/WARN]:     at$1.execute(
    [13:53:13] [Server thread/WARN]:     at org.bukkit.plugin.RegisteredListener.callEvent(
    [13:53:13] [Server thread/WARN]:     at org.bukkit.plugin.SimplePluginManager.fireEvent(
    [13:53:13] [Server thread/WARN]:     at org.bukkit.plugin.SimplePluginManager.callEvent(
    [13:53:13] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.PlayerConnection.a(
    [13:53:13] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.PacketPlayInWindowClick.a(SourceFile:31)
    [13:53:13] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.PacketPlayInWindowClick.a(SourceFile:9)
    [13:53:13] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$
    [13:53:13] [Server thread/WARN]:     at java.util.concurrent.Executors$
    [13:53:13] [Server thread/WARN]:     at
    [13:53:13] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44)
    [13:53:13] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.MinecraftServer.B(
    [13:53:13] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.DedicatedServer.B(
    [13:53:13] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.MinecraftServer.A(
    [13:53:13] [Server thread/WARN]:     at
    [13:53:13] [Server thread/WARN]:     at
    [13:53:13] [Server thread/WARN]: Caused by: error=2, No such file or directory
    [13:53:13] [Server thread/WARN]:     at java.lang.UNIXProcess.forkAndExec(Native Method)
    [13:53:13] [Server thread/WARN]:     at java.lang.UNIXProcess.<init>(
    [13:53:13] [Server thread/WARN]:     at java.lang.ProcessImpl.start(
    [13:53:13] [Server thread/WARN]:     at java.lang.ProcessBuilder.start(
    [13:53:13] [Server thread/WARN]:     ... 24 more
    This confuses me, because the file clearly DOES exist, and I'm able to access it fine:

    Thanks in advance!

    Never mind... Someone at one of my old posts said something that sparked an idea. I'm going to try a Runtime.getRuntime().exec(); with a specified environment.

    I have managed to solve the issue! I am now using:
    Code (Text):
    Runtime.getRuntime().exec("sh /root/minecraft/PlayerServers/" + server + "/", new String[] {}, new File("/root/minecraft/PlayerServers/" + server + "/"));
    #1 Swedz, Jun 26, 2016
    Last edited: Jun 26, 2016