@@ -51,6 +51,21 @@ def call_command(commands, logger, silent=False):
51
51
False
52
52
>>> call_command(['ls'], _LOGGER)
53
53
True
54
+ >>> try:
55
+ ... call_command(['ls','--invalid-option'], _LOGGER)
56
+ ... except CCPPError as e:
57
+ ... print(str(e))
58
+ Execution of 'ls --invalid-option' failed with code: 2
59
+ Error output: ls: unrecognized option '--invalid-option'
60
+ Try 'ls --help' for more information.
61
+ >>> try:
62
+ ... os.chdir(os.path.dirname(__file__))
63
+ ... call_command(['ls', os.path.basename(__file__), 'foo.bar.baz'], _LOGGER)
64
+ ... except CCPPError as e:
65
+ ... print(str(e))
66
+ Execution of 'ls xml_tools.py foo.bar.baz' failed with code: 2
67
+ xml_tools.py
68
+ Error output: ls: cannot access 'foo.bar.baz': No such file or directory
54
69
"""
55
70
result = False
56
71
outstr = ''
@@ -66,9 +81,17 @@ def call_command(commands, logger, silent=False):
66
81
result = False
67
82
else :
68
83
cmd = ' ' .join (commands )
69
- emsg = "Execution of '{}' failed with code:\n "
70
- outstr = emsg .format (cmd , err .returncode )
71
- outstr += "{}" .format (err .output )
84
+ outstr = f"Execution of '{ cmd } ' failed with code: { err .returncode } \n "
85
+ outstr += f"{ err .output .decode ('utf-8' , errors = 'replace' ).strip ()} "
86
+ if hasattr (err , 'stderr' ) and err .stderr :
87
+ stderr_str = err .stderr .decode ('utf-8' , errors = 'replace' ).strip ()
88
+ if stderr_str :
89
+ if err .output :
90
+ outstr += os .linesep
91
+ # end if
92
+ outstr += f"Error output: { stderr_str } "
93
+ # end if
94
+ # end if
72
95
raise CCPPError (outstr ) from err
73
96
# end if
74
97
# end of try
0 commit comments