Running a gradle task using gradle-tooling-api where the task itself launches an interactive shell of another application

I have created a task called runShell which can be used to run interactive shell ( such as groovysh or pig) by following the accepted answer in http://stackoverflow.com/questions/22567831/gradle-execute-groovy-interactive-shell-with-project-classpath. It works fine and the shell waits for input and gives proper output when I run it using gradle runShell on command line.

I have another application which uses gradle-tooling-api to run this task. When I try to run this task from my application, I cannot see the output from the task and also it doesn’t wait for the input. It just exits with success code.

I want to run the runShell task using the gradle tooling api and redirect input/output to the interactive shell which is being run by this task.

I’m setting the standardInput, standardOutput and standardError in the following way:

conn.newBuild().forTasks(*tasks).withArguments(*arguments).setStandardInput(System.in).setStandardOutput(System.out).setStandardError(System.out).run()

Any help would be really appreciated.