Subprocess
The subprocess
library enables straightforward execution of commands or binaries within Agent.
For this example, i'm taking back our previously created Agent my-parser
. We will execute a basic ls
for demo purposes.
agents/my-parser.py
from ..base import Base, logger
import subprocess # New import
class MyParserAgent(Base):
NAME = "MyParser"
ACTIVATED = True
VERSION = "1.0"
MISSION = "Yet another parser to parse"
def mission(self):
logger.info(f'[{self.NAME}] Checking in.')
# Use subprocess to run process. e.g. a basic ls, and retrieve files in a list
files = (subprocess.run("ls", capture_output=True, text=True).stdout).split('\n')
return files