-
-
Notifications
You must be signed in to change notification settings - Fork 428
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
[executeCommandLine] should return STDERR if STDOUT is empty #2114
Conversation
Signed-off-by: Andrew Fiddian-Green <[email protected]>
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/oh3-migrated-rule-executecommandline-command-fails/114027/10 |
LGTM |
@andrewfg at https://community.openhab.org/t/oh3-migrated-rule-executecommandline-command-fails/114027/5 you wrote that on OH2 you got the output from wget. I have looked at the code before #1700 but there is no access to getErrorStream(), so how could the stderr output of wget be read? About your PR, I would prefere to set the ProcessBuilder redirectErrorStream property to true. Then stdout and stderr outputs are merged in the correct chronology. |
I have no idea. All I can say is that on OH2 it returns the message, and on OH3 it does not. Maybe it is related to the change of Java version, or something like that??
Ok. Currently I have no idea how to do that though. But I will look into it tomorrow. However it might therefore require reverting the prior commit related to STDERR and STDOUT when ResultCode != 0. Since if both streams are merged in STDOUT then there's no need to look at STDERR anymore at all. Or?? |
I was hoping that someone with more java (ProcessBuilder) knowledge than me knows the answer.
You have to remove the errorFuture code and change
to
Yes |
Signed-off-by: Andrew Fiddian-Green <[email protected]>
@NorbertHD many thanks for the tips. I have made the changes that you suggest. @cpmeister it is ready to go (again) so can you please have a look at it (again) :) |
Signed-off-by: Andrew Fiddian-Green <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I think it would be useful if I add an extra JUnit test to confirm the STDERR redirection. |
Unit tests are always appreciated. Can you do that quickly? Otherwise a follow-up PR may be okay too. I would like to merge this into https://github.com/openhab/openhab-core/tree/3.0.x before building a 3.0.1 patch release for this weekend. |
I will try it today. |
Signed-off-by: Andrew Fiddian-Green <[email protected]>
@cweitkamp done :) |
@cweitkamp Afaik, this is an improvement, not a bug fix. |
@kaikreuzer hmm, not really. The prior PR only partly solved the regression from v2.5 (the case where errorCode != 0), but it did not resolve the case where errorCode == 0 and (yet) there was still data on STDERR. But I think we are talking of nuances here.. |
Are you really sure that STDERR was considered in 2.5? I wouldn't understand why this would have been the case - from the code it looks as if clearly only STDOUT was returned. |
Ok, diving a bit deeper, it seems you are right - the variable name in 2.5 was chosen misleadingly. The PumpStreamHandler indeed combines the output of STDOUT and STDERR into a single stream. |
Yes. And the test case is the 'wget' command which just returns an empty string in STDOUT, and returns the full connection status trace with its HTTP response headers in STDERR. The 'curl' command is similar.. |
Go ahead with this then @cweitkamp - I leave it to you :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems you are busy, so I'll take care of it.
Signed-off-by: Andrew Fiddian-Green <[email protected]>
Yes, I was. Thanks for taking care. |
…#2114) Signed-off-by: Andrew Fiddian-Green <[email protected]>
…#2114) Signed-off-by: Andrew Fiddian-Green <[email protected]> GitOrigin-RevId: 127724c
NOTE: this relates to Issue #2033 (comment)
If ErrorCode == 0 then executeCommandLineAndWaitResponse() would always return the response from STDOUT.
However on some Unix commands (e.g. wget, curl) if ErrorCode == 0 there is no response on STDOUT, but the commands return valid information on STDERR (even though there was not an error).
In this PR, if ErrorCode == 0, the return value of executeCommandLineAndWaitResponse() is
!"".equals(STDOUT) ? STDOUT : STDERR
Signed-off-by: Andrew Fiddian-Green [email protected]