Skip to content

Commit

Permalink
Remove script temp file once executed
Browse files Browse the repository at this point in the history
  • Loading branch information
profesorfalken committed Oct 7, 2018
1 parent 352c2e5 commit 18ea0f7
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/main/java/com/profesorfalken/jpowershell/PowerShell.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 18ea0f7

Please sign in to comment.