Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.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
Java 从Grails应用程序执行命令_Java_Grails_Groovy_Process - Fatal编程技术网

Java 从Grails应用程序执行命令

Java 从Grails应用程序执行命令,java,grails,groovy,process,Java,Grails,Groovy,Process,我想从我的Grails应用程序中执行一个svn delete。我在Grails控制台中测试了以下两项: "svn delete /usr/share/mydir".execute() Runtime.getRuntime().exec("svn delete /usr/share/mydir") 在这两种情况下,都会返回java.lang.Process的实例,但不会执行该命令(/usr/share/mydir) 此行为仅在应用程序在Linux(Ubuntu)上运行时发生。如果我在Windo

我想从我的Grails应用程序中执行一个
svn delete
。我在Grails控制台中测试了以下两项:

"svn delete /usr/share/mydir".execute()

Runtime.getRuntime().exec("svn delete /usr/share/mydir")
在这两种情况下,都会返回
java.lang.Process
的实例,但不会执行该命令(
/usr/share/mydir

此行为仅在应用程序在Linux(Ubuntu)上运行时发生。如果我在Windows上运行它,则会执行该命令

更新 按照Tim在评论中的建议,我更改了命令,以便它捕获流程输出:

def process = "svn delete /usr/share/mydir".execute()
def out = new StringBuilder()
process.waitForProcessOutput(out, new StringBuilder())

println "$out"
我现在明白了它失败的原因是:

错误svn:无法打开文件“/usr/share/mydir/.svn/lock”:权限 否认


下面的代码在CentOS上对我来说很好

    def scriptCom="/folderlocation/shellscript.sh"
    println "[[Running $scriptCom]]"
    def proc = scriptCom.execute()

    def oneMinute = 60000
    proc.waitForOrKill(oneMinute)

    if(proc.exitValue()!=0){
        println "[[return code: ${proc.exitValue()}]]"
        println "[[stderr: ${proc.err.text}]]"
        return null
    }else{
        println "[[stdout:$revisionid]]"
        return proc.in.text.readLines()
    }

waitForProcessOutput
和管道到通常的位置,没有显示它正在做什么而不是运行?这似乎是一个颠覆问题(由于早期的不完整更改)。能否先在此存储库上运行svn clean操作。出于可移植性的考虑,我建议通过Java的API直接与svn接口,而不是启动进程。面对同样的问题,这里有更新吗?