[exec] Cannot use quoted spaces in commands #6729
Labels
bug
An unexpected problem or unintended behavior of an add-on
PR pending
There is a pull request for resolving the issue
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());
toproc = 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
The text was updated successfully, but these errors were encountered: