Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Groovy 如何使用";执行;便携式的?_Groovy - Fatal编程技术网

Groovy 如何使用";执行;便携式的?

Groovy 如何使用";执行;便携式的?,groovy,Groovy,我有一个用于examle的groovyscript "mvn install".execute() 虽然这在linux上运行得很好,但在windows上会失败。在windows上,必须编写: "cmd /C mvn install".execute() 这有点令人担忧。我只是想通过使用来避免代码混乱,如果OS==windows,则使用。我敢肯定有人已经解决了这个问题,并为此提供了一些库。我就是找不到任何东西 由于String.execute()委托给操作系统,因此不应期望它是可移植的,但您可

我有一个用于examle的groovyscript

"mvn install".execute()
虽然这在linux上运行得很好,但在windows上会失败。在windows上,必须编写:

"cmd /C mvn install".execute()
这有点令人担忧。我只是想通过使用
来避免代码混乱,如果OS==windows,则使用
。我敢肯定有人已经解决了这个问题,并为此提供了一些库。我就是找不到任何东西

由于
String.execute()
委托给操作系统,因此不应期望它是可移植的,但您可以创建自己的可移植ish等价物

String.metaClass.pexecute = {
    if(/* Windows OS check goes here*/) {
        "cmd /C $delegate".execute()
    } else {
        delegate.execute()
    }
}
将此代码放在脚本的前面,您可以像这样调用
String.pexecute()
“mvn install”.pexecute()