Gradle Exec block doesn't redirect standardOutput to given output stream
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
add a comment |
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
Side note - that's Java 7 and not 8 in your logs output.
– Naman
Nov 23 '18 at 2:54
I simply printed theout
variable outsidegetJavaVersion()
without declaring it, and lo behold its an object reference!!
– Ryotsu
Nov 23 '18 at 8:19
@nullpointer: I know, This is what I want to get - Java version from givenworkingDir
.
– franta kocourek
Nov 23 '18 at 9:23
add a comment |
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
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
java gradle cmd windows-7 java-7
edited Nov 23 '18 at 2:55
Naman
44.5k11102204
44.5k11102204
asked Nov 23 '18 at 2:03
franta kocourekfranta kocourek
1,0061116
1,0061116
Side note - that's Java 7 and not 8 in your logs output.
– Naman
Nov 23 '18 at 2:54
I simply printed theout
variable outsidegetJavaVersion()
without declaring it, and lo behold its an object reference!!
– Ryotsu
Nov 23 '18 at 8:19
@nullpointer: I know, This is what I want to get - Java version from givenworkingDir
.
– franta kocourek
Nov 23 '18 at 9:23
add a comment |
Side note - that's Java 7 and not 8 in your logs output.
– Naman
Nov 23 '18 at 2:54
I simply printed theout
variable outsidegetJavaVersion()
without declaring it, and lo behold its an object reference!!
– Ryotsu
Nov 23 '18 at 8:19
@nullpointer: I know, This is what I want to get - Java version from givenworkingDir
.
– franta kocourek
Nov 23 '18 at 9:23
Side note - that's Java 7 and not 8 in your logs output.
– Naman
Nov 23 '18 at 2:54
Side note - that's Java 7 and not 8 in your logs output.
– Naman
Nov 23 '18 at 2:54
I simply printed the
out
variable outside getJavaVersion()
without declaring it, and lo behold its an object reference!!– Ryotsu
Nov 23 '18 at 8:19
I simply printed the
out
variable outside getJavaVersion()
without declaring it, and lo behold its an object reference!!– Ryotsu
Nov 23 '18 at 8:19
@nullpointer: I know, This is what I want to get - Java version from given
workingDir
.– franta kocourek
Nov 23 '18 at 9:23
@nullpointer: I know, This is what I want to get - Java version from given
workingDir
.– franta kocourek
Nov 23 '18 at 9:23
add a comment |
1 Answer
1
active
oldest
votes
Actually java -version
prints the message to the standard error and not standard output (stdout), so instead try:
errorOutput = out
Hi. Ouch, It never occured to me that the output could be written intoerrorOutput
. Do you know why the output is not written intostandardOutput
? Can you point me to some documentation regardingout
reference?
– franta kocourek
Nov 23 '18 at 9:26
@frantakocourek its the command that writes to the error stream not gradle. Tryjava -version 1>std.txt 2>err.txt
and have a look at the files.
– Ryotsu
Nov 23 '18 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 '18 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 '18 at 9:36
Ok, saved my day anyway :) Thanks.
– franta kocourek
Nov 23 '18 at 9:38
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Actually java -version
prints the message to the standard error and not standard output (stdout), so instead try:
errorOutput = out
Hi. Ouch, It never occured to me that the output could be written intoerrorOutput
. Do you know why the output is not written intostandardOutput
? Can you point me to some documentation regardingout
reference?
– franta kocourek
Nov 23 '18 at 9:26
@frantakocourek its the command that writes to the error stream not gradle. Tryjava -version 1>std.txt 2>err.txt
and have a look at the files.
– Ryotsu
Nov 23 '18 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 '18 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 '18 at 9:36
Ok, saved my day anyway :) Thanks.
– franta kocourek
Nov 23 '18 at 9:38
add a comment |
Actually java -version
prints the message to the standard error and not standard output (stdout), so instead try:
errorOutput = out
Hi. Ouch, It never occured to me that the output could be written intoerrorOutput
. Do you know why the output is not written intostandardOutput
? Can you point me to some documentation regardingout
reference?
– franta kocourek
Nov 23 '18 at 9:26
@frantakocourek its the command that writes to the error stream not gradle. Tryjava -version 1>std.txt 2>err.txt
and have a look at the files.
– Ryotsu
Nov 23 '18 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 '18 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 '18 at 9:36
Ok, saved my day anyway :) Thanks.
– franta kocourek
Nov 23 '18 at 9:38
add a comment |
Actually java -version
prints the message to the standard error and not standard output (stdout), so instead try:
errorOutput = out
Actually java -version
prints the message to the standard error and not standard output (stdout), so instead try:
errorOutput = out
edited Mar 4 at 22:11
Jay Taylor
8,30664373
8,30664373
answered Nov 23 '18 at 8:26
RyotsuRyotsu
590314
590314
Hi. Ouch, It never occured to me that the output could be written intoerrorOutput
. Do you know why the output is not written intostandardOutput
? Can you point me to some documentation regardingout
reference?
– franta kocourek
Nov 23 '18 at 9:26
@frantakocourek its the command that writes to the error stream not gradle. Tryjava -version 1>std.txt 2>err.txt
and have a look at the files.
– Ryotsu
Nov 23 '18 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 '18 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 '18 at 9:36
Ok, saved my day anyway :) Thanks.
– franta kocourek
Nov 23 '18 at 9:38
add a comment |
Hi. Ouch, It never occured to me that the output could be written intoerrorOutput
. Do you know why the output is not written intostandardOutput
? Can you point me to some documentation regardingout
reference?
– franta kocourek
Nov 23 '18 at 9:26
@frantakocourek its the command that writes to the error stream not gradle. Tryjava -version 1>std.txt 2>err.txt
and have a look at the files.
– Ryotsu
Nov 23 '18 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 '18 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 '18 at 9:36
Ok, saved my day anyway :) Thanks.
– franta kocourek
Nov 23 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 at 9:36
Ok, saved my day anyway :) Thanks.
– franta kocourek
Nov 23 '18 at 9:38
Ok, saved my day anyway :) Thanks.
– franta kocourek
Nov 23 '18 at 9:38
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Side note - that's Java 7 and not 8 in your logs output.
– Naman
Nov 23 '18 at 2:54
I simply printed the
out
variable outsidegetJavaVersion()
without declaring it, and lo behold its an object reference!!– Ryotsu
Nov 23 '18 at 8:19
@nullpointer: I know, This is what I want to get - Java version from given
workingDir
.– franta kocourek
Nov 23 '18 at 9:23