In Groovy I can run the Windows cmd shell directly and read the result like this:
def proc = "cmd /c dir".execute()
proc.wait()
println "stdout: ${proc.in.text}"
However, if I try this with PowerShell it blocks and won't return:
def proc = "powershell dir".execute()
I have tried
def proc = "powershell -NonInteractive dir".execute()
etc. - but they all block and I have to kill the Groovy script.
What's the equivalent of the /c
switch for cmd that you use with PowerShell to get the result to return to the script.
Use the -command parameter:
powershell -command "dir"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With