(no commit message)
This commit is contained in:
34
utils/shell_ops.py
Normal file
34
utils/shell_ops.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""Shell operation utilities for nanocode."""
|
||||
|
||||
import subprocess
|
||||
from .display import DIM, RESET
|
||||
|
||||
|
||||
def run_bash(cmd: str) -> str:
|
||||
"""Run a shell command and return output.
|
||||
|
||||
Args:
|
||||
cmd: Shell command to execute
|
||||
|
||||
Returns:
|
||||
Command output (stdout and stderr combined)
|
||||
"""
|
||||
proc = subprocess.Popen(
|
||||
cmd, shell=True,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
||||
text=True
|
||||
)
|
||||
output_lines = []
|
||||
try:
|
||||
while True:
|
||||
line = proc.stdout.readline()
|
||||
if not line and proc.poll() is not None:
|
||||
break
|
||||
if line:
|
||||
print(f" {DIM}│ {line.rstrip()}{RESET}", flush=True)
|
||||
output_lines.append(line)
|
||||
proc.wait(timeout=30)
|
||||
except subprocess.TimeoutExpired:
|
||||
proc.kill()
|
||||
output_lines.append("\n(timed out after 30s)")
|
||||
return "".join(output_lines).strip() or "(empty output)"
|
||||
Reference in New Issue
Block a user