execute an exe on windows using groovy script

你离开我真会死。 提交于 2020-03-21 03:59:15

问题


I am trying to execute a MIR3 (notification system) exe from the Groovy console:

def proc = "cmd /c C:\\Users\\AAithal\\Desktop\\MIR3\bin\\inConsole -H \"company.mir3.com\" -u \"user\" -p \"password\" -I -i \"Server\"".execute();
proc.waitForProcessOutput(System.out, System.err);
println "proc"

But get an error:

The filename, directory name, or volume label syntax is incorrect.

The path I have in the script is correct and I am able to execute the same from Windows CLI and getting the required output.

Please let me know where I am going wrong.


回答1:


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

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.




回答2:


Thanks Mike, this worked fine:)

def args = ['cmd', '/c', 'E:\\MIR3\\bin\\inConsole', '-H', 'company.mir3.com', '-u', 'user', '-p', 'password', '-I', '-i', MIR3Name, '-X', msgdata]


来源:https://stackoverflow.com/questions/43812005/execute-an-exe-on-windows-using-groovy-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!