Skip to content

Commit

Permalink
updated compiled files
Browse files Browse the repository at this point in the history
  • Loading branch information
libmartinito committed Oct 9, 2023
1 parent b37d076 commit 0f69764
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 31 deletions.
3 changes: 1 addition & 2 deletions compiled_starters/java/src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,5 @@ public static void main(String[] args) {
// System.err.printf("Err: %s\n", e.getMessage());
// System.exit(1);
// }


}
}
3 changes: 1 addition & 2 deletions solutions/java/01-init/code/src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,5 @@ public static void main(String[] args) {
System.err.printf("Err: %s\n", e.getMessage());
System.exit(1);
}


}
}
49 changes: 24 additions & 25 deletions solutions/java/01-init/diff/src/main/java/Main.java.diff
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@@ -4,53 +4,49 @@
@@ -4,52 +4,48 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -26,28 +26,7 @@
public static void main(String[] args) {
- // You can use print statements as follows for debugging, they'll be visible when running tests.
- System.out.println("Logs from your program will appear here!");
+ System.out.println(Arrays.toString(args));
+ String imageName = args[1];
+ String command = args[2];
+ String[] commandWithArgs = Arrays.copyOfRange(args, 2, args.length);
+ try {
+ ProcessBuilder processBuilder = new ProcessBuilder(commandWithArgs);
+ processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
+ processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
+
+ Process process = processBuilder.start();
+
+ int exitCode = process.waitFor();
+
+ if (exitCode != 0) {
+ System.err.printf("Err: %d\n", exitCode);
+ System.exit(1);
+ }
+ } catch (IOException | InterruptedException e) {
+ System.err.printf("Err: %s\n", e.getMessage());
+ System.exit(1);
+ }

-
- // Uncomment this block to pass the first stage!
- // System.out.println(Arrays.toString(args));
- // String imageName = args[1];
Expand All @@ -70,8 +49,28 @@
- // System.err.printf("Err: %s\n", e.getMessage());
- // System.exit(1);
- // }

-
+ System.out.println(Arrays.toString(args));
+ String imageName = args[1];
+ String command = args[2];
+ String[] commandWithArgs = Arrays.copyOfRange(args, 2, args.length);
+ try {
+ ProcessBuilder processBuilder = new ProcessBuilder(commandWithArgs);
+ processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
+ processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
+
+ Process process = processBuilder.start();
+
+ int exitCode = process.waitFor();
+
+ if (exitCode != 0) {
+ System.err.printf("Err: %d\n", exitCode);
+ System.exit(1);
+ }
+ } catch (IOException | InterruptedException e) {
+ System.err.printf("Err: %s\n", e.getMessage());
+ System.exit(1);
+ }
}
-}
\ No newline at end of file
+}
3 changes: 1 addition & 2 deletions starter_templates/java/src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,5 @@ public static void main(String[] args) {
// System.err.printf("Err: %s\n", e.getMessage());
// System.exit(1);
// }


}
}

0 comments on commit 0f69764

Please sign in to comment.