Skip to content

Instantly share code, notes, and snippets.

@n1chre
Last active December 5, 2016 09:32
Show Gist options
  • Save n1chre/eaa5213c1f05732113663db9517b7e6a to your computer and use it in GitHub Desktop.
Save n1chre/eaa5213c1f05732113663db9517b7e6a to your computer and use it in GitHub Desktop.
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
/**
* Created by fhrenic on 12/11/2016.
*/
public class Runner {
public static void main(String[] args) throws IOException {
List<Process> processes = new LinkedList<>();
URL url = Runner.class.getClassLoader().getResource("");
if (url == null) { // won't happen
throw new IllegalStateException("Can't get working directory");
}
File root = new File(url.getPath());
// Create commands here
String[] cmd = new String[]{"sh", "-c", "'echo hello'"};
for (String nodename : Config.getNodeNames()) {
processes.add(
new ProcessBuilder(cmd)
.directory(root)
.redirectOutput(ProcessBuilder.Redirect.INHERIT)
.redirectError(ProcessBuilder.Redirect.INHERIT)
.start()
);
}
loop();
processes.forEach(Process::destroy);
}
private static void loop(){
System.out.println("> procceses started");
System.out.println("> type exit to stop");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
while (true) {
System.out.print("> ");
if ("exit".equalsIgnoreCase(in.readLine())) { break; }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment