How to run PowerShell scripts from Kotlin?

2019-04-12 00:23发布

问题:

How can I run a Powershell script using Kotlin?

I tried to port some Java code I found on StackOverflow, but I couldn't get it to work. I also tried the following:

Runtime.getRuntime().exec("powershell.exe [path to file]")

but that didn't work either.

What is the simplest way to do this in Kotlin?

回答1:

Please add "-File" argument, e.g. script should be like this:

Runtime.getRuntime().exec("powershell.exe -File d:\\my-script.ps1")

Please see PowerShell documentation here.