INNER CODE UNIT · Python
execute_command
iamgreggarcia/codesherpa · localserver/main.py:204
async def execute_command(command: str) -> str:
"""
Executes the given command in a shell and returns the result.
Args:
command (str): The command to execute.
Returns:
str: The result of the command execution.
"""
try:
result = subprocess.run(command.split(), capture_output=True, text=True)
return f"Result:\n{result.stdout}"
except subprocess.CalledProcessError as e:
logger.error(
f"Error executing command: {e}. Return code: {e.returncode}. Output: {e.output}"
)
return f"Error executing command: {str(e)}"