Run a command from a Grails application

I want to execute svn delete from my Grails application. In the Grails console, I tested both versions:

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

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

This behavior is only observed when running the application on Linux (Ubuntu). If I run it on Windows, the command will be executed.

Update

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

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

Now I see that the reason for his failure is that:

Svn error: Cannot open file '/usr/share/mydir/.svn/lock': Permission denied

+6
source share
1 answer

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() } 
+3
source

Source: https://habr.com/ru/post/919831/


All Articles