Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

execute command from Grails app

I want to perform an svn delete from my Grails app. I tested out both of the following in the Grails console:

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

Runtime.getRuntime().exec("svn delete /usr/share/mydir")

In both cases, a instance of java.lang.Process is returned, but the command does not get executed (/usr/share/mydir is not deleted).

This behaviour only happens when the app is running on Linux (Ubuntu). If I run it on Windows, the command does get executed.

Update

Following Tim's advice in the comments, I changed the command so that it captures the process output:

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

println "$out"

I now see that the reason it's failing is because:

error svn: Can't open file '/usr/share/mydir/.svn/lock': Permission denied

like image 388
Dónal Avatar asked Jul 06 '12 07:07

Dónal


1 Answers

The below code works fine for me on 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()
    }
like image 113
thk Avatar answered Sep 22 '22 19:09

thk