问题
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