Add stdout and stderr to debug output for shell_command (#14465)

This commit is contained in:
Nathan Henrie authored and Pascal Vizeli committed 2018-05-16 13:47:41 +02:00
1 parent 25dcddfeef
commit 1053473111
2 files changed
+51 -5

No files matched your search

+13 -5
View File
@@ -68,8 +68,9 @@ def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
cmd,
loop=hass.loop,
stdin=None,
stdout=asyncio.subprocess.DEVNULL,
stderr=asyncio.subprocess.DEVNULL)
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
else:
# Template used. Break into list and use create_subprocess_exec
# (which uses shell=False) for security
@@ -80,12 +81,19 @@ def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
*shlexed_cmd,
loop=hass.loop,
stdin=None,
stdout=asyncio.subprocess.DEVNULL,
stderr=asyncio.subprocess.DEVNULL)
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
process = yield from create_process
yield from process.communicate()
stdout_data, stderr_data = yield from process.communicate()
if stdout_data:
_LOGGER.debug("Stdout of command: `%s`, return code: %s:\n%s",
cmd, process.returncode, stdout_data)
if stderr_data:
_LOGGER.debug("Stderr of command: `%s`, return code: %s:\n%s",
cmd, process.returncode, stderr_data)
if process.returncode != 0:
_LOGGER.exception("Error running command: `%s`, return code: %s",
cmd, process.returncode)