Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run a PowerShell command from groovy the same way as "cmd /c <command>".execute()?

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.

like image 487
WILLIAM WOODMAN Avatar asked Mar 23 '15 21:03

WILLIAM WOODMAN


1 Answers

Use the -command parameter:

powershell -command "dir"

like image 107
Malk Avatar answered Sep 23 '22 04:09

Malk