17 lines
690 B
Python
Executable File
17 lines
690 B
Python
Executable File
#!/usr/bin/env python3
|
|
import subprocess
|
|
|
|
def run_command(command: str):
|
|
"""Executes a Linux command, waits for completion, and returns output."""
|
|
try:
|
|
# shell=True allows running full command strings with pipes/wildcards
|
|
# text=True returns strings instead of bytes
|
|
result = subprocess.run(
|
|
command, shell=True, check=True, capture_output=True, text=True
|
|
)
|
|
|
|
return {"success": True, "stdout": result.stdout, "stderr": result.stderr}
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
# Handles errors if the Linux command returns a non-zero exit code
|
|
return {"success": False, "stdout": e.stdout, "stderr": e.stderr} |