Some checks failed
CLI Tests / test-cli (push) Has been cancelled
Cross-Node Transaction Testing / transaction-test (push) Has been cancelled
Deploy to Testnet / deploy-testnet (push) Has been cancelled
Multi-Node Stress Testing / stress-test (push) Has been cancelled
Security Scanning / security-scan (push) Has been cancelled
- Moved core/ directory to aitbc_cli/core/ to make it a proper subpackage - Updated aitbc_cli.py to load from new path - Simplified aitbc_cli/__init__.py to use normal import instead of spec_from_file_location - Updated all core imports to use aitbc_cli.core prefix - Copied utils files (wallet_daemon_client, error_handling, crypto_utils, subprocess) to aitbc_cli/utils/ - Fixed wallet list command to work with new structure - This fixes ModuleNotFoundError for aitbc_cli.core submodules
31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
import subprocess
|
|
import sys
|
|
from typing import List, Optional, Union, Any
|
|
from . import error, output
|
|
import logging
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def run_subprocess(cmd: List[str], check: bool = True, capture_output: bool = True, shell: bool = False, **kwargs: Any) -> Optional[Union[str, subprocess.CompletedProcess]]:
|
|
"""Run a subprocess command safely with logging"""
|
|
try:
|
|
# Always use shell=False for security
|
|
result = subprocess.run(cmd, check=check, capture_output=capture_output, text=True, shell=False, **kwargs)
|
|
|
|
if capture_output:
|
|
return result.stdout.strip()
|
|
return result
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
error(f"Command failed with exit code {e.returncode}")
|
|
if capture_output and getattr(e, 'stderr', None):
|
|
logger.info(e.stderr, file=sys.stderr)
|
|
if check:
|
|
sys.exit(e.returncode)
|
|
return getattr(e, 'stdout', None) if capture_output else None
|
|
except Exception as e:
|
|
error(f"Failed to execute command: {e}")
|
|
if check:
|
|
sys.exit(1)
|
|
return None
|