diff --git a/README.md b/README.md
index 118956a..8611292 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,7 @@ Simple Java API that allows to interact with PowerShell console
.close();
```
-#### New JPowerShell v3.0 is out
+#### New JPowerShell v3 is out
The version 3 of JPowerShell includes an important revision and rewrite of most of the code that improves performance and stability.
@@ -103,6 +103,9 @@ The variables that can be configured in jPowerShell are:
*maxWait*: the maximum wait in ms for the command to execute. Default value is 10000
+*tempFolder*: if you set this variable jPowerShell will use this folder in order to store temporary the scripts to execute.
+By default the environment variable _java.io.tmpdir_ will be used.
+
## Advanced usage
### Setting the PowerShell executable path
diff --git a/pom.xml b/pom.xml
index 40cb5df..d8058b4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
com.profesorfalken
jPowerShell
- 3.0.4
+ 3.1.0
jar
jPowerShell
diff --git a/src/main/java/com/profesorfalken/jpowershell/PowerShell.java b/src/main/java/com/profesorfalken/jpowershell/PowerShell.java
index 30e65ec..06c757e 100644
--- a/src/main/java/com/profesorfalken/jpowershell/PowerShell.java
+++ b/src/main/java/com/profesorfalken/jpowershell/PowerShell.java
@@ -55,8 +55,9 @@ public class PowerShell implements AutoCloseable {
private static final String DEFAULT_LINUX_EXECUTABLE = "powershell";
// Config values
- private int waitPause = 10;
+ private int waitPause = 5;
private long maxWait = 10000;
+ private File tempFolder = null;
// Variables used for script mode
private boolean scriptMode = false;
@@ -89,6 +90,8 @@ public PowerShell configuration(Map config) {
: PowerShellConfig.getConfig().getProperty("waitPause"));
this.maxWait = Long.valueOf((config != null && config.get("maxWait") != null) ? config.get("maxWait")
: PowerShellConfig.getConfig().getProperty("maxWait"));
+ this.tempFolder = (config != null && config.get("tempFolder") != null) ? getTempFolder(config.get("tempFolder"))
+ : getTempFolder(PowerShellConfig.getConfig().getProperty("tempFolder"));
} catch (NumberFormatException nfe) {
logger.log(Level.SEVERE,
"Could not read configuration. Using default values.", nfe);
@@ -352,7 +355,7 @@ private File createWriteTempFile(BufferedReader srcReader) {
File tmpFile = null;
try {
- tmpFile = File.createTempFile("psscript_" + new Date().getTime(), ".ps1");
+ tmpFile = File.createTempFile("psscript_" + new Date().getTime(), ".ps1", this.tempFolder);
if (!tmpFile.exists()) {
return null;
}
@@ -471,4 +474,15 @@ private long getPID() {
return -1;
}
+
+ //Return the temp folder File object or null if the path does not exist
+ private File getTempFolder(String tempPath) {
+ if (tempPath != null) {
+ File folder = new File(tempPath);
+ if (folder.exists()) {
+ return folder;
+ }
+ }
+ return null;
+ }
}
diff --git a/src/main/resources/jpowershell.properties b/src/main/resources/jpowershell.properties
index 33cfe8f..1a7e5b2 100644
--- a/src/main/resources/jpowershell.properties
+++ b/src/main/resources/jpowershell.properties
@@ -12,4 +12,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
waitPause=5
-maxWait=10000
\ No newline at end of file
+maxWait=10000
+tempFolder=e:\\tmp
\ No newline at end of file