且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Groovy脚本在Windows上执行exe

更新时间:2023-12-05 14:22:04

当您有大量参数时,有时***使用ProcessBuilder,例如

When you have a load of arguments it's sometimes better to user ProcessBuilder e.g.

def sout = new StringBuilder(), serr = new StringBuilder()
//def args = ['cmd', '/c', 'dir']
def args = ['cmd', '/c', 'C:\\Users\\AAithal\\Desktop\\MIR3\\bin\\inConsole', '-H', 'company.mir3.com', '-u', 'user', '-p', 'password', '-I', '-i', 'Server']
def proc = new ProcessBuilder( args )
Process process = proc.start()
process.consumeProcessOutput( sout, serr )
process.waitForOrKill( 2000 )
println sout

我已包括注释掉的 def args = ['cmd ','/ c','dir'] 行,因此您可以使用一个简单的示例来测试一切是否正常,然后转到更复杂的调用。

I've included the commented out def args = ['cmd', '/c', 'dir'] line so you can test that everything works with a simple example then move onto the more complicated call.