@@ -46,6 +46,8 @@ public class PowerShell implements AutoCloseable {
4646 // Writer to send commands
4747 private PrintWriter commandWriter ;
4848
49+ private BufferedReader outputReader ;
50+
4951 // Threaded session variables
5052 private boolean closed = false ;
5153 private ExecutorService executorService ;
@@ -68,7 +70,7 @@ private PowerShell() {
6870 }
6971
7072 /**
71- * Allows to override jPowerShell configuration using a map of key/value <br>
73+ * Allows overriding jPowerShell configuration using a map of key/value <br>
7274 * Default values are taken from file <i>jpowershell.properties</i>, which can
7375 * be replaced just setting it on project classpath
7476 * <p>
@@ -114,8 +116,8 @@ public PowerShell configuration(Map<String, String> config) {
114116 }
115117
116118 /**
117- * Creates a session in PowerShell console an returns an instance which allows
118- * to execute commands in PowerShell context.<br>
119+ * Creates a session in PowerShell console which returns an instance which allows
120+ * executing commands in PowerShell context.<br>
119121 * It uses the default PowerShell installation in the system.
120122 *
121123 * @return an instance of the class
@@ -126,8 +128,8 @@ public static PowerShell openSession() throws PowerShellNotAvailableException {
126128 }
127129
128130 /**
129- * Creates a session in PowerShell console an returns an instance which allows
130- * to execute commands in PowerShell context.<br>
131+ * Creates a session in PowerShell console which returns an instance which allows
132+ * executing commands in PowerShell context.<br>
131133 * This method allows to define a PowersShell executable path different from default
132134 *
133135 * @param customPowerShellExecutablePath the path of powershell executable. If you are using
@@ -140,8 +142,8 @@ public static PowerShell openSession(String customPowerShellExecutablePath) thro
140142 }
141143
142144 /**
143- * Creates a session in PowerShell console an returns an instance which allows
144- * to execute commands in PowerShell context.<br>
145+ * Creates a session in PowerShell console which returns an instance which allows
146+ * executing commands in PowerShell context.<br>
145147 * This method allows to define a PowersShell executable path different from default
146148 *
147149 * @param customPowerShellExecutablePath the path of powershell executable. If you are using
@@ -158,11 +160,11 @@ public static PowerShell openSession(String customPowerShellExecutablePath, Map<
158160
159161 String powerShellExecutablePath = customPowerShellExecutablePath == null ? (OSDetector .isWindows () ? DEFAULT_WIN_EXECUTABLE : DEFAULT_LINUX_EXECUTABLE ) : customPowerShellExecutablePath ;
160162
161- return powerShell .initalize (powerShellExecutablePath );
163+ return powerShell .initialize (powerShellExecutablePath );
162164 }
163165
164166 // Initializes PowerShell console in which we will enter the commands
165- private PowerShell initalize (String powerShellExecutablePath ) throws PowerShellNotAvailableException {
167+ private PowerShell initialize (String powerShellExecutablePath ) throws PowerShellNotAvailableException {
166168 String codePage = PowerShellCodepage .getIdentifierByCodePageName (Charset .defaultCharset ().name ());
167169 ProcessBuilder pb ;
168170
@@ -193,6 +195,8 @@ private PowerShell initalize(String powerShellExecutablePath) throws PowerShellN
193195 //Prepare writer that will be used to send commands to powershell
194196 this .commandWriter = new PrintWriter (new OutputStreamWriter (new BufferedOutputStream (p .getOutputStream ())), true );
195197
198+ this .outputReader = new BufferedReader (new InputStreamReader (p .getInputStream ()));
199+
196200 // Init thread pool. 2 threads are needed: one to write and read console and the other to close it
197201 this .executorService = Executors .newFixedThreadPool (2 );
198202
@@ -219,8 +223,7 @@ public PowerShellResponse executeCommand(String command) {
219223
220224 checkState ();
221225
222- PowerShellCommandProcessor commandProcessor = new PowerShellCommandProcessor ("standard" , p .getInputStream (),
223- this .waitPause , this .scriptMode );
226+ PowerShellCommandProcessor commandProcessor = new PowerShellCommandProcessor (this .outputReader , this .waitPause , this .scriptMode );
224227 Future <String > result = executorService .submit (commandProcessor );
225228
226229 // Launch command
@@ -251,7 +254,7 @@ public PowerShellResponse executeCommand(String command) {
251254 }
252255
253256 /**
254- * Execute a single command in PowerShell consolscriptModee and gets result
257+ * Execute a single command in PowerShell console scriptMode and gets result
255258 *
256259 * @param command the command to execute
257260 * @return response with the output of the command
@@ -269,7 +272,7 @@ public static PowerShellResponse executeSingleCommand(String command) {
269272 }
270273
271274 /**
272- * Allows to chain command executions providing a more fluent API.<p>
275+ * Allows chaining command executions providing a more fluent API.<p>
273276 * <p>
274277 * This method allows also to optionally handle the response in a closure
275278 *
@@ -447,7 +450,7 @@ public void close() {
447450 commandWriter .close ();
448451 try {
449452 if (p .isAlive ()) {
450- p . getInputStream () .close ();
453+ outputReader .close ();
451454 }
452455 } catch (IOException ex ) {
453456 logger .log (Level .SEVERE ,
0 commit comments