Here is my code:
public class PowerShellCommand {
public static void main(String[] args) throws Exception {
PowerShellCommand call=new PowerShellCommand();
ids=(call.commandsilent("powershell.exe Get-Process | Format-Table ` Id"));
processes=(call.commandsilent("powershell.exe Get-Process | Format-Table ` ProcessName -AutoSize"));
}
String commandsilent(String command)throws Exception
{String output="";
//String command = "powershell.exe your command";
//Getting the version
//command = "powershell.exe Get-Process";
// Executing the command
Process powerShellProcess = Runtime.getRuntime().exec(command);
// Getting the results
powerShellProcess.getOutputStream().close();
String line;
// System.out.println("Standard Output:");
BufferedReader stdout = new BufferedReader(new InputStreamReader(
powerShellProcess.getInputStream()));
while ((line = stdout.readLine()) != null) {
output+=line+",";
//System.out.println(line);
}
stdout.close();
//System.out.println("Standard Error:");
BufferedReader stderr = new BufferedReader(new InputStreamReader(
powerShellProcess.getErrorStream()));
stderror="";
while ((line = stderr.readLine()) != null) {
stderror+=line;
// System.out.println(line);
}
stderr.close();
//System.out.println("Done");
return output;
}
}
I have got the process ids in the string array processes[] and process id in string array ids[]
But I can't find any method to differentiate between them.
question from:
https://stackoverflow.com/questions/65650978/how-to-distinguish-between-a-system-and-normal-process-by-getting-processname-an 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…