PowerShell call from Java
Does anyone know of a good library for calling powershell scripts from Java? I am currently creating a separate process (powershell.exe) and then parsing the output, but it would be nice if I could use PowerShell's "power" by returning objects from a powershell call.
Edit:
Otherwise, does anyone else do such an interop? What method are you using?
+2
a source to share
3 answers
Actually, the answer to this question shows how to invoke Powershell from Java.
If your Powershell script is script.ps1 you should use
String cmd = "powershell C:\\path\\to\\your\\script\\script.ps1"
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(command);
process.getOutputStream().close();
It looks like me.
+2
a source to share