You should probably use an AtomicBoolean for "running".

Is there an up-to-date description of how to build a plugin? If so, I'll make an "exec" plugin to do this kind of stuff. Assuming it's okay I build off of the provided code.

~~ Robert.

Jim Moore wrote:
FWIW, I wrote a method that gives me better control than I saw elsewhere:

  void runCmd(String cmd, File baseDir) {
    println cmd

    def sout = new StringBuffer()
    def serr = new StringBuffer()
    def outProc = Runtime.runtime.exec(cmd, [] as String[], baseDir)
    def running = true
    def bufferPrinter = {buffer ->
      def lastIndex = 0
      while(running) {
        def length = buffer.length()
        if (length > lastIndex) {
          print buffer.subSequence(lastIndex, length)
          lastIndex = length
        }
        Thread.sleep(100)
      }
    }
    Thread.start bufferPrinter.curry(sout)
    Thread.start bufferPrinter.curry(serr)

    outProc.consumeProcessOutput(sout, serr)
    try {
      outProc.waitFor()
    }
    finally {
      running = false
    }

    if (outProc.exitValue()) {
      println "Error code: ${outProc.exitValue()}"
      System.exit(1)
    }
  }


On Wed, Nov 18, 2009 at 9:04 AM, Robert Fischer <robert.fisc...@smokejumperit.com <mailto:robert.fisc...@smokejumperit.com>> wrote:

    How can I exec a shell command and see the output?  Normally, the
    Ant "exec" task works fine for this, but when I invoke 'exec' in
    Gradle, I don't get any output to the screen.  Is there some
    equivalent to Gant's "execute" tool?

    ~~ Robert.

    ---------------------------------------------------------------------
    To unsubscribe from this list, please visit:

      http://xircles.codehaus.org/manage_email




---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


Reply via email to