使用Groovy脚本在Windows上执行exe [英] execute an exe on windows using groovy script
问题描述
我正在尝试从Groovy控制台执行MIR3(通知系统)exe:
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"
但是出现错误:
文件名,目录名或卷标语法不正确。
The filename, directory name, or volume label syntax is incorrect.
我在脚本中使用的路径是正确的,并且我能够从Windows CLI执行相同的操作并获得所需的输出。
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.
推荐答案
当您有大量参数时,有时最好使用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.
这篇关于使用Groovy脚本在Windows上执行exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!