[Bug]: Execute a process - Single and double quotes are not parsed correctly
Apache Hop version?
2.15.0
Java version?
17.0.2
Operating system
Linux
What happened?
Steps to reproduce:
- Create a Data grid transform, with a single column named
command. Enter the following entries (assuming/work/hop/configis an existing folder on your machine):
-
ls -la /work/hop/config(with no quotes) -
ls -la "/work/hop/config"(with double quotes) -
ls -la '/work/hop/config'(with single quotes)
- Link this to an Execute a process transform, set
$[0D]as line delimiter and grab result, error, and exit code in some fields - Link to a Write to log transform to get the output
In a normal Linux terminal all the three commands above will produce the same output (they list the contents of the /work/hop/config folder). In Hop only the first row produces the correct output, the others will throw an error such as Folder '"/work/hop/config"' does not exist.
Issue Priority
Priority: 2
Issue Component
Component: Transforms
A possible workaround is:
- in Data grid split the command in chunks, using a field for each chunk. In the example above they could be:
-
command=ls -
option_la=-la -
folder=/work/hop/config
- in Execute a process enable the option Arguments in fields, then set
commandas Process field, set alsooption_laandfolderin the Argument fields
A chunk in the Data grid can include spaces and special characters (this is why you would have used the quotes, most likely)
Execute a process is using Runtime.exec(), which has some strange "features".
We might be better off using a processBuilder
The command indeed is /usr/bin/ls. The rest are arguments.
Hi @mattcasters,
the problem is indeed that you are required to enable the option Arguments in fields to process the arguments correctly (see workaround above).
Without that option, I'd expect to pass a complex command line in the command field as I would do in a normal (Linux) terminal: it actually works when the command doesn't include single or double quotes. When there are those, it seems that command and arguments are just split by spaces, without taking into account that something delimited by quotes is actually a single argument even if it contains spaces.