Skip to content
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] Cannot use quoted spaces in commands #6729

Closed
cpiber opened this issue Jan 1, 2020 · 1 comment · Fixed by #6819
Closed

[exec] Cannot use quoted spaces in commands #6729

cpiber opened this issue Jan 1, 2020 · 1 comment · Fixed by #6819
Labels
bug An unexpected problem or unintended behavior of an add-on PR pending There is a pull request for resolving the issue

Comments

@cpiber
Copy link

cpiber commented Jan 1, 2020

Expected Behavior

The command gets executed as if entered into the command line.

Current Behavior

The command is passed to Runtime.getRuntime().exec as string parameter, causing it to get parsed by Java's Tokenizer, which ignores quotes and always splits at spaces.
This means that an argument with spaces surrounded by quotes still gets split into two (or more).

Possible Solution

Line 174 of ExecHandler.java (https://github.com/openhab/openhab-addons/blob/2.5.x/bundles/org.openhab.binding.exec/src/main/java/org/openhab/binding/exec/internal/handler/ExecHandler.java#L174):
Change from proc = rt.exec(commandLine.toString()); to proc = rt.exec(new String[] {"bash", "-c", commandLine.toString() });.
Possibly include a check whether on *nix systems or on Windows (change 'bash' to 'cmd' and '-c' to '/c' on MS Windows).

Steps to Reproduce (for Bugs)

Set command to include an argument with spaces, for example: wget --post-data "some data" http://example.com

Your Environment

openHABian 4.19.75-v7l+ #1270 SMP Tue Sep 24 18:51:41 BST 2019 armv7l

@cpiber cpiber added the bug An unexpected problem or unintended behavior of an add-on label Jan 1, 2020
@cpiber
Copy link
Author

cpiber commented Jan 1, 2020

Alternative: use the same system as ExecUtil (https://github.com/openhab/openhab-core/blob/b03b3e9b0026c0915a7370eb17e8f80405bfa497/bundles/org.openhab.core.io.net/src/main/java/org/openhab/core/io/net/exec/ExecUtil.java#L58) which provides a way to replace spaces between arguments with @@

9037568 added a commit to 9037568/openhab2-addons that referenced this issue Jan 12, 2020
as was done in the 1.x binding.

Fixes openhab#6729.

Signed-off-by: 9037568 <namraccr@gmail.com>
@9037568 9037568 added the PR pending There is a pull request for resolving the issue label Jan 12, 2020
@wborn wborn changed the title [Exec binding] Spaces in command [exec] Cannot use quoted spaces in commands Jan 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on PR pending There is a pull request for resolving the issue
Projects
None yet
2 participants