golang preps
@@ -79,6 +79,29 @@ public class BinaryExecutionHelper {
return result;
}
+ public String executeGoCommand(String guess) {
+ try {
+ File execFile = createTempExecutable("wrongsecrets-golang");
+ String result;
+ if (Strings.isNullOrEmpty(guess)) {
+ result = executeCommand(execFile, "spoil");
+ } else {
+ result = executeCommand(execFile, "guess " + guess);
+ }
+ deleteFile(execFile);
+ log.info("stdout challenge {}: {}", challengeNumber, result);
+ return result;
+ } catch (IOException | NullPointerException | InterruptedException e) {
+ log.warn("Error executing:", e);
+ return ERROR_EXECUTION;
+ }
+ }
+
+ private void deleteFile(File execFile) {
+ if (!execFile.delete()) {
+ log.info("Deleting the file {} failed...", execFile.getPath());
+ }
+ }
public String executeCommand(String guess, String fileName) {
if (Strings.isNullOrEmpty((guess))) {
@@ -87,9 +110,7 @@ public class BinaryExecutionHelper {
try {
File execFile = createTempExecutable(fileName);
String result = executeCommand(execFile, guess);
- if (!execFile.delete()) {
- log.info("Deleting the file {} failed...", execFile.getPath());
- }
+ deleteFile(execFile);
log.info("stdout challenge {}: {}", challengeNumber, result);
return result;
} catch (IOException | NullPointerException | InterruptedException e) {
