forked from Nirman-Rathod/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExcecuteScript.java
More file actions
35 lines (31 loc) · 1016 Bytes
/
ExcecuteScript.java
File metadata and controls
35 lines (31 loc) · 1016 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.java.powershell;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ExcecuteScript {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
String command = "powershell.exe \"C:\\PowerShellVersion.ps1\" ";
Process powerShellProcess = Runtime.getRuntime().exec(command);
powerShellProcess.getOutputStream().close();
String line;
System.out.println("Output:");
BufferedReader stdout = new BufferedReader(new InputStreamReader(
powerShellProcess.getInputStream()));
while ((line = stdout.readLine()) != null) {
System.out.println(line);
}
stdout.close();
System.out.println("Error:");
BufferedReader stderr = new BufferedReader(new InputStreamReader(
powerShellProcess.getErrorStream()));
while ((line = stderr.readLine()) != null) {
System.out.println(line);
}
stderr.close();
System.out.println("Done");
}
}