-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[Exec] Properly split command & pipe support #6819
Conversation
- Implemented @@ manual split (@see https://www.openhab.org/docs/configuration/actions.html#exec-actions) - Pass to shell if not manually split (detect shell via https://stackoverflow.com/a/31547504/7508309, permission by author) Fixes #6729 Added benefit: Pass to shell allows for pipes Signed-off-by: Constantin Piber <cp.piber@gmail.com>
Travis tests were successfulHey @cpiber, |
Similar to #6815, but allows for pipes and doesn't change output buffer functionality |
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.
One major concern with this is it will break anyone who is already passing bash
or cmd
as the command to be executed. Might still be worth doing, but we may need additional input (@J-N-K or @kaikreuzer ?).
Some fixes will be needed, in any event.
...penhab.binding.exec/src/main/java/org/openhab/binding/exec/internal/handler/ExecHandler.java
Outdated
Show resolved
Hide resolved
...penhab.binding.exec/src/main/java/org/openhab/binding/exec/internal/handler/ExecHandler.java
Outdated
Show resolved
Hide resolved
...penhab.binding.exec/src/main/java/org/openhab/binding/exec/internal/handler/ExecHandler.java
Outdated
Show resolved
Hide resolved
...penhab.binding.exec/src/main/java/org/openhab/binding/exec/internal/handler/ExecHandler.java
Outdated
Show resolved
Hide resolved
...penhab.binding.exec/src/main/java/org/openhab/binding/exec/internal/handler/ExecHandler.java
Outdated
Show resolved
Hide resolved
...penhab.binding.exec/src/main/java/org/openhab/binding/exec/internal/handler/ExecHandler.java
Outdated
Show resolved
Hide resolved
...penhab.binding.exec/src/main/java/org/openhab/binding/exec/internal/handler/ExecHandler.java
Outdated
Show resolved
Hide resolved
...penhab.binding.exec/src/main/java/org/openhab/binding/exec/internal/handler/ExecHandler.java
Outdated
Show resolved
Hide resolved
...penhab.binding.exec/src/main/java/org/openhab/binding/exec/internal/handler/ExecHandler.java
Outdated
Show resolved
Hide resolved
...penhab.binding.exec/src/main/java/org/openhab/binding/exec/internal/handler/ExecHandler.java
Show resolved
Hide resolved
Changes as suggested by @9037568 Signed-off-by: Constantin Piber <cp.piber@gmail.com>
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.
@9037568 See comments and new commit
Travis tests were successfulHey @cpiber, |
Signed-off-by: Constantin Piber <cp.piber@gmail.com>
Travis tests were successfulHey @cpiber, |
Comment only; please don't forget us Windows users. (I have no idea if any this has an impact there.) |
Sorry, new to this. Tested on Linux with: |
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.
Addressed latest changes with commentary.
Signed-off-by: Constantin Piber <cp.piber@gmail.com>
Signed-off-by: Constantin Piber <cp.piber@gmail.com>
Travis tests were successfulHey @cpiber, |
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.
Since I haven't seen feedback from TPTB, I guess I'll have to ask you to fix the breakage issue, too.
In order to not break existing setups, each of the conditions starting at line 198 needs to check if the received command already starts with one of the shell commands, and if so, not prepend the shell command to the received command.
Please also eliminate the remaining occurrences of commandLine.toString()
.
Signed-off-by: Constantin Piber <cp.piber@gmail.com>
Travis tests were successfulHey @cpiber, |
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.
I think this should be the last set of changes needed...
...penhab.binding.exec/src/main/java/org/openhab/binding/exec/internal/handler/ExecHandler.java
Outdated
Show resolved
Hide resolved
...penhab.binding.exec/src/main/java/org/openhab/binding/exec/internal/handler/ExecHandler.java
Outdated
Show resolved
Hide resolved
...penhab.binding.exec/src/main/java/org/openhab/binding/exec/internal/handler/ExecHandler.java
Outdated
Show resolved
Hide resolved
only invoke shell if the first WORD is a shell-program, not just the beginning of the string (ex. shout shouldn't match) Signed-off-by: Constantin Piber <cp.piber@gmail.com>
Travis tests were successfulHey @cpiber, |
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. Thanks for this work, @cpiber !
} else { | ||
// Invoke shell with 'c' option and pass string | ||
logger.debug("Passing to shell for parsing command."); | ||
if (getOperatingSystemType() == OS.WINDOWS) { |
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.
I have a question here: Why don't you get the operating system type once and then use the local variable in a switch-statement. Are your sure that everything other than OS.WINDOWS
and OS.UNKNOWN
is a supported *nix? And please add the unsupported OS-name to the warn-message logger.warn("OS '{}' not supported, please split commands manually!", getOperatingSystemName());
).
Edit: I found it below. But the if-else is not very intuitive here. Please use a switch-statement.
|
||
Process proc = null; | ||
try { | ||
proc = rt.exec(commandLine.toString()); | ||
proc = rt.exec(cmdArray); | ||
} catch (Exception e) { |
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.
Is it necessary to catch Exception
here? According to the docs there is a limited number of exceptions, I think we can omit the NPE if we make sure that none of the commands is null (which should be done anyway).
@@ -193,7 +245,7 @@ public void run() { | |||
isr.close(); | |||
} catch (IOException e) { | |||
logger.error("An exception occurred while reading the stdout when executing '{}' : '{}'", |
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.
And this should be warn
, also below. error
is reserved for the framework of occasions where the stability of the system may be affected.
return System.getProperty("os.name"); | ||
} | ||
|
||
} |
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.
Please run mvn spotless:apply
after the code issues are done.
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.
What exactly does that do?
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.
Okay so it runs some more tests, I get
[ERROR] Failed to execute goal com.diffplug.spotless:spotless-maven-plugin:1.24.3:apply (default-cli) on project org.openhab.binding.feed.tests: Execution default-cli of goal com.diffplug.spotless:spotless-maven-plugin:1.24.3:apply failed: Overlapping text edits -> [Help 1]
What do I do? Can't find any info on that.
Also doesn't seem to by because of my changes (I didn't touch feed binding, at least I don't think)
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.
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.
Reset the changes in other bindings and use mvn spotless:apply -pl bundles\org.openhab.binding.exec
to only re-format the exec binding.
Signed-off-by: Constantin Piber <cp.piber@gmail.com>
Travis tests were successfulHey @cpiber, |
* [Exec] Properly split command Signed-off-by: Constantin Piber <cp.piber@gmail.com>
* [Exec] Properly split command Signed-off-by: Constantin Piber <cp.piber@gmail.com> Signed-off-by: leluna <hengrui.jiang@googlemail.com>
* [Exec] Properly split command Signed-off-by: Constantin Piber <cp.piber@gmail.com> Signed-off-by: Hans-Reiner Hoffmann <hans-reiner.hoffmann@gmx.de>
* [Exec] Properly split command Signed-off-by: Constantin Piber <cp.piber@gmail.com>
I used to have a exec thing to track CPU/MOBO temperatures, it worked fine for more than a year until the recent updates. I have tired multiple combinations for the command (below) and none of the work, i have updated the misc/exec.whitelist every time, the error I get is shown below. Thing exec:command:core1temp "System" @ "Exec" [ command="/bin/cat /sys/class/hwmon/hwmon2/temp3_input", transform="JS(milli.js)", interval=10, autorun=true ] 2020-06-23 11:55:47.099 [WARN ] [mmon.WrappedScheduledExecutorService] - Scheduled runnable ended with an exception: |
Not much point opening a months old pull request, just because it mentions exec. You appear to have run into the javascript issue described here - |
* [Exec] Properly split command Signed-off-by: Constantin Piber <cp.piber@gmail.com>
* [Exec] Properly split command Signed-off-by: Constantin Piber <cp.piber@gmail.com>
* [Exec] Properly split command Signed-off-by: Constantin Piber <cp.piber@gmail.com>
* [Exec] Properly split command Signed-off-by: Constantin Piber <cp.piber@gmail.com>
* [Exec] Properly split command Signed-off-by: Constantin Piber <cp.piber@gmail.com> Signed-off-by: Daan Meijer <daan@studioseptember.nl>
* [Exec] Properly split command Signed-off-by: Constantin Piber <cp.piber@gmail.com>
Fixes [exec] Cannot use quoted spaces in commands #6729
Added benefit: Pass to shell allows for pipes
Signed-off-by: Constantin Piber cp.piber@gmail.com