- /**
- * Simple command to test that the environment / stdout are working
- * correctly.
- *
- * @param args
- * Command-line arguments
- */
- public static void main(String[] args) {
- List<String> command = Arrays.asList("ls", "-l");
- executeCommand(command);
- }
-
- private static boolean executeCommand(List<String> command) {
- try {
- /* "echo" the command to stdout */
- StringJoiner sj = new StringJoiner(" ", "$ ", "");
- command.stream().forEach(sj::add);
- System.out.println(sj.toString());
-
- ProcessBuilder builder = new ProcessBuilder(command);
- builder.redirectErrorStream(true);
- builder.redirectOutput(Redirect.INHERIT);
-
- Process p = builder.start();
- int ret = p.waitFor();
-
- System.out.println("(returned from command)");
-
- return (ret == 0);
-
- } catch (IOException | InterruptedException e) {
- return false;
- }
- }