From 18ea0f78d0a67b19cb8bc3c2b2f3d5bbd711bded Mon Sep 17 00:00:00 2001 From: profesorfalken Date: Sun, 7 Oct 2018 21:51:13 +0200 Subject: [PATCH] Remove script temp file once executed --- .../com/profesorfalken/jpowershell/PowerShell.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/profesorfalken/jpowershell/PowerShell.java b/src/main/java/com/profesorfalken/jpowershell/PowerShell.java index 6f4aa55..4cbdb5e 100644 --- a/src/main/java/com/profesorfalken/jpowershell/PowerShell.java +++ b/src/main/java/com/profesorfalken/jpowershell/PowerShell.java @@ -325,22 +325,23 @@ public PowerShellResponse executeScript(BufferedReader srcReader) { * @param params the parameters of the script * @return response with the output of the command */ - @SuppressWarnings("WeakerAccess") public PowerShellResponse executeScript(BufferedReader srcReader, String params) { - + PowerShellResponse response; if (srcReader != null) { File tmpFile = createWriteTempFile(srcReader); if (tmpFile != null) { this.scriptMode = true; - return executeCommand(tmpFile.getAbsolutePath() + " " + params); + response = executeCommand(tmpFile.getAbsolutePath() + " " + params); + tmpFile.delete(); } else { - return new PowerShellResponse(true, "Cannot create temp script file!", false); + response = new PowerShellResponse(true, "Cannot create temp script file!", false); } } else { logger.log(Level.SEVERE, "Script buffered reader is null!"); - return new PowerShellResponse(true, "Script buffered reader is null!", false); + response = new PowerShellResponse(true, "Script buffered reader is null!", false); } + return response; } // Writes a temp powershell script file based on the srcReader