Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose node task's execResult #11

Closed
ljohnston opened this issue Apr 14, 2014 · 4 comments
Closed

Expose node task's execResult #11

ljohnston opened this issue Apr 14, 2014 · 4 comments

Comments

@ljohnston
Copy link

The node task should expose it's execResult as the Gradle Exec task does.

Use case: I want to ignore the exit value of some of my node-based test tasks (i.e. ignoreExitValue = true), but retrieve their actual success/failure status via execResult.exitValue.

Thanks,
Lance

@johnrengelman
Copy link
Contributor

+1 - I'm just looking at this now, because I want to redirect the output/error streams to something that isn't the console but then on an error condition, print out the entire output so it's not interleaved with the output from other tasks.

@srs
Copy link
Owner

srs commented Apr 16, 2014

Will pull in your pull request i a couple of hours. Thanks.

@srs srs closed this as completed Apr 17, 2014
@nkoterba
Copy link

@johnrengelman Can you share how you were able to redirect output/error streams?

I'm trying to do the same thing, but standardOutput and errorOutput are not exposed on the Node/Npm Tasks (which wrap and insulate an internal Exec runner) so not sure how to do this. My thought was:

standardOutput = new ByteArrayOutputStream()
    errorOutput = standardOutput
    ignoreExitValue = true
    doLast {
        if (result.exitValue != 0) {
            println(standardOutput.toString())
            throw new GradleException("exec failed; see output above")
        }
    }

But standardOutput as I mentioned isn't defined on NodeTask or NpmTask.

@nkoterba
Copy link

I was able to get something to work, although I'm not sure it's the best strategy. If either of you have better suggestion, would appreciate it.

ignoreExitValue = true
    def execRunner = null
    execOverrides {
        execRunner = it
        it.standardOutput = new ByteArrayOutputStream()
        it.errorOutput = it.standardOutput
    }
    doLast {
        if (result.exitValue != 0) {
            println(execRunner.standardOutput.toString())
            throw new GradleException("exec failed; see output above")
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants