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


The downside to cross-platform tools is that you only have a common set of tools for each platform - this is not possible with Java. You can do JNI or use the method you already tried



+1


a source


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


I found Powershell Bridge (PSB) . Still need to study it though

0


a source







All Articles