Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/main/java/com/profesorfalken/jpowershell/PowerShell.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public class PowerShell implements AutoCloseable {
private boolean scriptMode = false;
public static final String END_SCRIPT_STRING = "--END-JPOWERSHELL-SCRIPT--";

private String tempDirectory;

// Private constructor. Instance using openSession method
private PowerShell() {
}
Expand Down Expand Up @@ -89,6 +91,7 @@ public PowerShell configuration(Map<String, String> config) {
: PowerShellConfig.getConfig().getProperty("waitPause"));
this.maxWait = Long.valueOf((config != null && config.get("maxWait") != null) ? config.get("maxWait")
: PowerShellConfig.getConfig().getProperty("maxWait"));
this.tempDirectory = (config != null && config.get("tempDirectory") != null) ? ((String)config.get("tempDirectory")) : null;
} catch (NumberFormatException nfe) {
logger.log(Level.SEVERE,
"Could not read configuration. Using default values.", nfe);
Expand Down Expand Up @@ -350,9 +353,12 @@ private File createWriteTempFile(BufferedReader srcReader) {

BufferedWriter tmpWriter = null;
File tmpFile = null;
File dir = null;
if(null != tempDirectory)
dir = new File(tempDirectory);

try {
tmpFile = File.createTempFile("psscript_" + new Date().getTime(), ".ps1");
tmpFile = File.createTempFile("psscript_" + new Date().getTime(), ".ps1",dir);
if (!tmpFile.exists()) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,14 @@ public void testCheckEmptyResponse() {
public void testLongCommand() {
System.out.println("testLongCommand");
if (OSDetector.isWindows()) {
Map<String, String> config = new HashMap<>();
config.put("maxWait","30000");
PowerShell powerShell = PowerShell.openSession();
PowerShellResponse response = powerShell
PowerShellResponse response = powerShell.configuration(config)
.executeCommand("Get-WMIObject -List | Where{$_.name -match \"^Win32_\"} | Sort Name");
System.out.println("Long list:" + response.getCommandOutput());

Assert.assertFalse(powerShell.isLastCommandInError());
Assert.assertFalse(powerShell.configuration(config).isLastCommandInError());
Assert.assertTrue(response.getCommandOutput().length() > 1000);

powerShell.close();
Expand Down