-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛fix: when terraform error not output
- Loading branch information
1 parent
782c00a
commit 6c96c55
Showing
6 changed files
with
50 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import logging | ||
import subprocess | ||
from subprocess import Popen, PIPE | ||
from typing import Tuple, List | ||
|
||
|
||
class SubprocessHandler: | ||
def run_command(self, command: str) -> Tuple[int, List[str], List[str]]: | ||
try: | ||
process = Popen( | ||
command, | ||
shell=True, | ||
stdout=PIPE, | ||
stderr=PIPE, | ||
universal_newlines=True | ||
) | ||
|
||
stdout_lines, stderr_lines = process.communicate() | ||
|
||
output_lines = stdout_lines.strip().split('\n') if stdout_lines else [] | ||
error_lines = stderr_lines.strip().split('\n') if stderr_lines else [] | ||
|
||
if process.returncode == 0: | ||
return process.returncode, output_lines | ||
return process.returncode, error_lines | ||
|
||
except subprocess.CalledProcessError as err: | ||
logging.error( | ||
f"Error executing command, code: {err.returncode}. Error:\n{err.output}" | ||
) | ||
return err.returncode, [], [err.output] | ||
|
||
except Exception as e: | ||
logging.error(f"An error occurred: {e}") | ||
return 1, [], [str(e)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters