So I have a code which runs powershell scripts, I had it return me the name and the starttime of the currently running processes. What I want is for this output to be stored in an array list because I want to be able to iterate through the names and start times of these applications.
public class Main {
public static void main(String[] args) throws IOException {
//Getting the version
String command = "Get-wmiobject -Class win32_Product";
// Executing the command
Process p = Runtime.getRuntime().exec("powershell -command "Get-Process | select name, starttime"");
// Getting the results
p.getOutputStream();
String line;
System.out.println("Standard Output:");
BufferedReader stdout = new BufferedReader(new InputStreamReader(
p.getInputStream()));
while ((line = stdout.readLine()) != null) {
System.out.println(line);
}
stdout.close();
System.out.println("Standard Error:");
BufferedReader stderr = new BufferedReader(new InputStreamReader(
p.getErrorStream()));
while ((line = stderr.readLine()) != null) {
System.out.println(line);
}
stderr.close();
System.out.println("Done");
}
}
This is the code, and here I want to store the output (p.getOutputStream) in an arraylist so then I can iterate through it. I did have a look at the similar questions but couldn’t solve it
Abdullah Jamsheed is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.