Skip to content

Commit

Permalink
✨ feat: added function to run script and get outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
huangyz0918 committed May 3, 2024
1 parent 78266bc commit ed6c917
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions agent/utils/system.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import re
import sys
import yaml
import subprocess
from rich.console import Console

from agent.utils import Config
Expand Down Expand Up @@ -199,3 +201,24 @@ def read_file_to_string(file_path: str):
return file.read()
except FileNotFoundError:
return None


def run_command(command):
"""
Run a command in the shell and return the output and error.
:param command: the input command to run.
:return: the output and error.
"""
try:
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)

output = ''
while True:
line = process.stdout.readline()
if not line and process.poll() is not None:
break
output += line

return output
except Exception as e:
return str(e)

0 comments on commit ed6c917

Please sign in to comment.