Gradle Exec block doesn't redirect standardOutput to given output stream












1














I have block like this one:



task print() {
doLast {
println("stop-1")
println(getJavaVersion())
println("stop-3")
}
}

def getJavaVersion() {
def out = new ByteArrayOutputStream()
exec {
workingDir 'C:/Program Files/Java/jdk1.7.0_80/bin'
commandLine 'cmd', '/c', 'java', '-version'
standardOutput = out
}

println 'stop-2'
return out.toString()
}


And I would expect that the output will be printed inside doLast block of print task, but it's printed just after exec block.



This is the output:



Executing tasks: [print]

Parallel execution with configuration on demand is an incubating feature.

> Task :gcUnicorn-core:print
stop-1
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
stop-2

stop-3

BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed


As you can see, the output stream is empty.



I went trough Gradle's documentation and many examples I found, but have no luck to solve it.



Gradle: 4.10.2, Windows: 7, jdk1.8.0_192



Thank you for any advice.










share|improve this question
























  • Side note - that's Java 7 and not 8 in your logs output.
    – nullpointer
    Nov 23 at 2:54










  • I simply printed the out variable outside getJavaVersion() without declaring it, and lo behold its an object reference!!
    – Ryotsu
    Nov 23 at 8:19










  • @nullpointer: I know, This is what I want to get - Java version from given workingDir.
    – franta kocourek
    Nov 23 at 9:23
















1














I have block like this one:



task print() {
doLast {
println("stop-1")
println(getJavaVersion())
println("stop-3")
}
}

def getJavaVersion() {
def out = new ByteArrayOutputStream()
exec {
workingDir 'C:/Program Files/Java/jdk1.7.0_80/bin'
commandLine 'cmd', '/c', 'java', '-version'
standardOutput = out
}

println 'stop-2'
return out.toString()
}


And I would expect that the output will be printed inside doLast block of print task, but it's printed just after exec block.



This is the output:



Executing tasks: [print]

Parallel execution with configuration on demand is an incubating feature.

> Task :gcUnicorn-core:print
stop-1
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
stop-2

stop-3

BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed


As you can see, the output stream is empty.



I went trough Gradle's documentation and many examples I found, but have no luck to solve it.



Gradle: 4.10.2, Windows: 7, jdk1.8.0_192



Thank you for any advice.










share|improve this question
























  • Side note - that's Java 7 and not 8 in your logs output.
    – nullpointer
    Nov 23 at 2:54










  • I simply printed the out variable outside getJavaVersion() without declaring it, and lo behold its an object reference!!
    – Ryotsu
    Nov 23 at 8:19










  • @nullpointer: I know, This is what I want to get - Java version from given workingDir.
    – franta kocourek
    Nov 23 at 9:23














1












1








1







I have block like this one:



task print() {
doLast {
println("stop-1")
println(getJavaVersion())
println("stop-3")
}
}

def getJavaVersion() {
def out = new ByteArrayOutputStream()
exec {
workingDir 'C:/Program Files/Java/jdk1.7.0_80/bin'
commandLine 'cmd', '/c', 'java', '-version'
standardOutput = out
}

println 'stop-2'
return out.toString()
}


And I would expect that the output will be printed inside doLast block of print task, but it's printed just after exec block.



This is the output:



Executing tasks: [print]

Parallel execution with configuration on demand is an incubating feature.

> Task :gcUnicorn-core:print
stop-1
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
stop-2

stop-3

BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed


As you can see, the output stream is empty.



I went trough Gradle's documentation and many examples I found, but have no luck to solve it.



Gradle: 4.10.2, Windows: 7, jdk1.8.0_192



Thank you for any advice.










share|improve this question















I have block like this one:



task print() {
doLast {
println("stop-1")
println(getJavaVersion())
println("stop-3")
}
}

def getJavaVersion() {
def out = new ByteArrayOutputStream()
exec {
workingDir 'C:/Program Files/Java/jdk1.7.0_80/bin'
commandLine 'cmd', '/c', 'java', '-version'
standardOutput = out
}

println 'stop-2'
return out.toString()
}


And I would expect that the output will be printed inside doLast block of print task, but it's printed just after exec block.



This is the output:



Executing tasks: [print]

Parallel execution with configuration on demand is an incubating feature.

> Task :gcUnicorn-core:print
stop-1
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
stop-2

stop-3

BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed


As you can see, the output stream is empty.



I went trough Gradle's documentation and many examples I found, but have no luck to solve it.



Gradle: 4.10.2, Windows: 7, jdk1.8.0_192



Thank you for any advice.







java gradle cmd windows-7 java-7






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 at 2:55









nullpointer

40.7k1081161




40.7k1081161










asked Nov 23 at 2:03









franta kocourek

9151014




9151014












  • Side note - that's Java 7 and not 8 in your logs output.
    – nullpointer
    Nov 23 at 2:54










  • I simply printed the out variable outside getJavaVersion() without declaring it, and lo behold its an object reference!!
    – Ryotsu
    Nov 23 at 8:19










  • @nullpointer: I know, This is what I want to get - Java version from given workingDir.
    – franta kocourek
    Nov 23 at 9:23


















  • Side note - that's Java 7 and not 8 in your logs output.
    – nullpointer
    Nov 23 at 2:54










  • I simply printed the out variable outside getJavaVersion() without declaring it, and lo behold its an object reference!!
    – Ryotsu
    Nov 23 at 8:19










  • @nullpointer: I know, This is what I want to get - Java version from given workingDir.
    – franta kocourek
    Nov 23 at 9:23
















Side note - that's Java 7 and not 8 in your logs output.
– nullpointer
Nov 23 at 2:54




Side note - that's Java 7 and not 8 in your logs output.
– nullpointer
Nov 23 at 2:54












I simply printed the out variable outside getJavaVersion() without declaring it, and lo behold its an object reference!!
– Ryotsu
Nov 23 at 8:19




I simply printed the out variable outside getJavaVersion() without declaring it, and lo behold its an object reference!!
– Ryotsu
Nov 23 at 8:19












@nullpointer: I know, This is what I want to get - Java version from given workingDir.
– franta kocourek
Nov 23 at 9:23




@nullpointer: I know, This is what I want to get - Java version from given workingDir.
– franta kocourek
Nov 23 at 9:23












1 Answer
1






active

oldest

votes


















1














Actually java -verison prints the message to the standard error and not the standard output, so instead try



errorOutput = out






share|improve this answer























  • Hi. Ouch, It never occured to me that the output could be written into errorOutput. Do you know why the output is not written into standardOutput? Can you point me to some documentation regarding out reference?
    – franta kocourek
    Nov 23 at 9:26












  • @frantakocourek its the command that writes to the error stream not gradle. Try java -version 1>std.txt 2>err.txt and have a look at the files.
    – Ryotsu
    Nov 23 at 9:28












  • I will accept your answer. Thank you for it! Can you please point me to some documentation about it? I would like to know why it writes into error stream. Thank you.
    – franta kocourek
    Nov 23 at 9:30






  • 1




    @frantakocourek actually i'd expect java's man page to document where it prints the version of java but it dosen't but i did find this stackoverflow.com/questions/23464917/…
    – Ryotsu
    Nov 23 at 9:36












  • Ok, saved my day anyway :) Thanks.
    – franta kocourek
    Nov 23 at 9:38











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439846%2fgradle-exec-block-doesnt-redirect-standardoutput-to-given-output-stream%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Actually java -verison prints the message to the standard error and not the standard output, so instead try



errorOutput = out






share|improve this answer























  • Hi. Ouch, It never occured to me that the output could be written into errorOutput. Do you know why the output is not written into standardOutput? Can you point me to some documentation regarding out reference?
    – franta kocourek
    Nov 23 at 9:26












  • @frantakocourek its the command that writes to the error stream not gradle. Try java -version 1>std.txt 2>err.txt and have a look at the files.
    – Ryotsu
    Nov 23 at 9:28












  • I will accept your answer. Thank you for it! Can you please point me to some documentation about it? I would like to know why it writes into error stream. Thank you.
    – franta kocourek
    Nov 23 at 9:30






  • 1




    @frantakocourek actually i'd expect java's man page to document where it prints the version of java but it dosen't but i did find this stackoverflow.com/questions/23464917/…
    – Ryotsu
    Nov 23 at 9:36












  • Ok, saved my day anyway :) Thanks.
    – franta kocourek
    Nov 23 at 9:38
















1














Actually java -verison prints the message to the standard error and not the standard output, so instead try



errorOutput = out






share|improve this answer























  • Hi. Ouch, It never occured to me that the output could be written into errorOutput. Do you know why the output is not written into standardOutput? Can you point me to some documentation regarding out reference?
    – franta kocourek
    Nov 23 at 9:26












  • @frantakocourek its the command that writes to the error stream not gradle. Try java -version 1>std.txt 2>err.txt and have a look at the files.
    – Ryotsu
    Nov 23 at 9:28












  • I will accept your answer. Thank you for it! Can you please point me to some documentation about it? I would like to know why it writes into error stream. Thank you.
    – franta kocourek
    Nov 23 at 9:30






  • 1




    @frantakocourek actually i'd expect java's man page to document where it prints the version of java but it dosen't but i did find this stackoverflow.com/questions/23464917/…
    – Ryotsu
    Nov 23 at 9:36












  • Ok, saved my day anyway :) Thanks.
    – franta kocourek
    Nov 23 at 9:38














1












1








1






Actually java -verison prints the message to the standard error and not the standard output, so instead try



errorOutput = out






share|improve this answer














Actually java -verison prints the message to the standard error and not the standard output, so instead try



errorOutput = out







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 23 at 9:31

























answered Nov 23 at 8:26









Ryotsu

550312




550312












  • Hi. Ouch, It never occured to me that the output could be written into errorOutput. Do you know why the output is not written into standardOutput? Can you point me to some documentation regarding out reference?
    – franta kocourek
    Nov 23 at 9:26












  • @frantakocourek its the command that writes to the error stream not gradle. Try java -version 1>std.txt 2>err.txt and have a look at the files.
    – Ryotsu
    Nov 23 at 9:28












  • I will accept your answer. Thank you for it! Can you please point me to some documentation about it? I would like to know why it writes into error stream. Thank you.
    – franta kocourek
    Nov 23 at 9:30






  • 1




    @frantakocourek actually i'd expect java's man page to document where it prints the version of java but it dosen't but i did find this stackoverflow.com/questions/23464917/…
    – Ryotsu
    Nov 23 at 9:36












  • Ok, saved my day anyway :) Thanks.
    – franta kocourek
    Nov 23 at 9:38


















  • Hi. Ouch, It never occured to me that the output could be written into errorOutput. Do you know why the output is not written into standardOutput? Can you point me to some documentation regarding out reference?
    – franta kocourek
    Nov 23 at 9:26












  • @frantakocourek its the command that writes to the error stream not gradle. Try java -version 1>std.txt 2>err.txt and have a look at the files.
    – Ryotsu
    Nov 23 at 9:28












  • I will accept your answer. Thank you for it! Can you please point me to some documentation about it? I would like to know why it writes into error stream. Thank you.
    – franta kocourek
    Nov 23 at 9:30






  • 1




    @frantakocourek actually i'd expect java's man page to document where it prints the version of java but it dosen't but i did find this stackoverflow.com/questions/23464917/…
    – Ryotsu
    Nov 23 at 9:36












  • Ok, saved my day anyway :) Thanks.
    – franta kocourek
    Nov 23 at 9:38
















Hi. Ouch, It never occured to me that the output could be written into errorOutput. Do you know why the output is not written into standardOutput? Can you point me to some documentation regarding out reference?
– franta kocourek
Nov 23 at 9:26






Hi. Ouch, It never occured to me that the output could be written into errorOutput. Do you know why the output is not written into standardOutput? Can you point me to some documentation regarding out reference?
– franta kocourek
Nov 23 at 9:26














@frantakocourek its the command that writes to the error stream not gradle. Try java -version 1>std.txt 2>err.txt and have a look at the files.
– Ryotsu
Nov 23 at 9:28






@frantakocourek its the command that writes to the error stream not gradle. Try java -version 1>std.txt 2>err.txt and have a look at the files.
– Ryotsu
Nov 23 at 9:28














I will accept your answer. Thank you for it! Can you please point me to some documentation about it? I would like to know why it writes into error stream. Thank you.
– franta kocourek
Nov 23 at 9:30




I will accept your answer. Thank you for it! Can you please point me to some documentation about it? I would like to know why it writes into error stream. Thank you.
– franta kocourek
Nov 23 at 9:30




1




1




@frantakocourek actually i'd expect java's man page to document where it prints the version of java but it dosen't but i did find this stackoverflow.com/questions/23464917/…
– Ryotsu
Nov 23 at 9:36






@frantakocourek actually i'd expect java's man page to document where it prints the version of java but it dosen't but i did find this stackoverflow.com/questions/23464917/…
– Ryotsu
Nov 23 at 9:36














Ok, saved my day anyway :) Thanks.
– franta kocourek
Nov 23 at 9:38




Ok, saved my day anyway :) Thanks.
– franta kocourek
Nov 23 at 9:38


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439846%2fgradle-exec-block-doesnt-redirect-standardoutput-to-given-output-stream%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks