diff --git a/Execute Shell Command/execute_shell_command.py b/Execute Shell Command/execute_shell_command.py index 077c370e..23a7140c 100644 --- a/Execute Shell Command/execute_shell_command.py +++ b/Execute Shell Command/execute_shell_command.py @@ -8,11 +8,11 @@ def execute_shell_command(command): out, err = proc.communicate() return_code = proc.returncode if err: - print(str(err)) + print(err.decode('utf8', errors='ignore')) return out, return_code except Exception as err: - print("Exception Occurred while executing module : %s", str(err)) - return 105 + print(f"Exception Occurred while executing module : {err}") + return b'', 105 if __name__ == '__main__': command ='echo Deepak' diff --git a/Execute Shell Command/execute_shell_command_test.py b/Execute Shell Command/execute_shell_command_test.py index db063049..835f517c 100644 --- a/Execute Shell Command/execute_shell_command_test.py +++ b/Execute Shell Command/execute_shell_command_test.py @@ -7,6 +7,10 @@ def test_shell_command(self): result, status = shell.execute_shell_command('echo Khanna') self.assertEqual(result.decode('utf8').rstrip("\r\n"), 'Khanna') + def test_shell_command_non_zero_status(self): + result, status = shell.execute_shell_command('non_existent_command_12345') + self.assertNotEqual(status, 0) + self.assertIsInstance(result, bytes) + if __name__ == '__main__': unittest.main(verbosity=2) -