Skip to content

[inputs.exec] Allow declaring command as array, similar to [inputs.execd], [outputs.exec] and [outputs.execd] #17913

@JoseAPortilloJSC

Description

@JoseAPortilloJSC

Use Case

[[inputs.exec]]
  ## One program to run.
  ## NOTE: process and each argument should each be their own string
  command = ['powershell', '-File', 'C:\Script Dir\Script File.ps1', '-Param1', 'value 1', '-Param2', 'value 2']
[[inputs.exec]]
  ## One program to run.
  ## NOTE: process and each argument should each be their own string
  command = [
    'powershell', '-File', 'C:\Script Dir\Script File.ps1',
    '-Param1', 'value 1',
    '-Param2', 'veryyyyyyyyyyyyyyyyyyyyyyyyyyyy loooooooooooooooooooooong value 2',
    '-InputPath', 'C:\dir\windows path with spaces\file name with spaces.bin',
    ...other long list of parameters
  ]

Expected behavior

Maybe resurrect the now-deprecated single-command command setting, this time as single-command array type?

Telegraf would allow declaring the command setting as an array, as in the plugins cited in the title. The commands setting would be left as it is.

To execute the command, Telegraf would call osExec.Command (run_windows.go, run_notwinodws.go) with the provided array of items, without any modification (no unescaping, no globbing, no processing).

Actual behavior

Not possible:

  • the now-deprecated 'command' setting was of string type, not array type.
  • the supported 'commands' setting is an array of strings, one for each command.
    • each command string is later split by shellQuote.Split (run_windows.go, run_notwinodws.go), introducing some issues as shown in Issue 1792

Additional info

A command like this:

command = [
  'powershell', '-File', 'C:\Script Dir\Script File.ps1',
  '-Param1', 'value 1',
  '-Param2', 'veryyyyyyyyyyyyyyyyyyyyyyyyyyyy loooooooooooooooooooooong value 2',
  '-InputPath', '\\server\share\windows path with spaces\script name with spaces.bin'
]

...would yield a splitCmd array (run_windows.go, run_notwinodws.go) like this passed to osExec.Command():

[0] = "powershell"
[1] = "-File"
[2] = "C:\\Script Dir\\Script File.ps1"   <-- each backslash **displayed** by the debugger as \\
[3] = "-Param1"
[4] = "value 1"
...
[8] = "\\\\server\\share\\windows path with spaces\\script name with spaces.bin"   <-- each backslash **displayed** as \\

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestRequests for new plugin and for new features to existing plugins

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions