Solved Make java code run shell script (.sh)

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

  1. I have been working on making a private plugin for personal use only that needs to make another spigot server boot up.

    Note: My servers are run on Linux (Ubuntu 16.04), just keep that in mind.

    I have made the shell script executable using chmod, and I can manually startup the script. However, I'd like my plugin to be able to do that when I do a command. I have setup the command, but I can't seem to get it to execute the shell script.

    I have this so far:
    Code (Text):
    ProcessBuilder pb = new ProcessBuilder("/root/minecraft/PlayerServers/" + server + "/");
    Process p = pb.start();
    There's no errors in console, it just doesn't start the script.
    Any thoughts on why this could be?

    Thanks in advance!
  2. I think you'd find this helpful
  3. How would I do this in my situation? Since I don't need any arguments, it just needs to run the shell script.
  4. Hmm, you could just execute it using
    Code (Java):
    then. Never tried it personally but it seems like it could do the trick.
  5. I meant as for the command, should I do "sh /root/minecraft/PlayerServers/" + server + "/" or "/root/minecraft/PlayerServers/" + server + "/"?
  6. If you decide to hard code the path of the directory, then it would need to be from your machine's root directory. If you wanna do things dynamically (which I recommend), I'd suggest using
    Code (Java):
    and playing around with it so that you could make it so that the shell script is in, lets say, the server's directory.