Camel.interpreters.subprocess interpreter
SubprocessInterpreter
SubprocessInterpreter is a class for executing code files or code strings in a subprocess.
This class handles the execution of code in different scripting languages (currently Python and Bash) within a subprocess, capturing their stdout and stderr streams, and allowing user checking before executing code strings.
Parameters:
- require_confirm (bool, optional): If True, prompt user before running code strings for security. (default: :obj:
True
) - print_stdout (bool, optional): If True, print the standard output of the executed code. (default: :obj:
False
) - print_stderr (bool, optional): If True, print the standard error of the executed code. (default: :obj:
True
) - execution_timeout (int, optional): Maximum time in seconds to wait for code execution to complete. (default: :obj:
60
)
init
run_file
Executes a code file in a subprocess and captures its output.
Parameters:
- file (Path): The path object of the file to run.
- code_type (str): The type of code to execute (e.g., ‘python’, ‘bash’).
Returns:
str: A string containing the captured stdout and stderr of the executed code.
run
Generates a temporary file with the given code, executes it, and deletes the file afterward.
Parameters:
- code (str): The code string to execute.
- code_type (str): The type of code to execute (e.g., ‘python’, ‘bash’).
Returns:
str: A string containing the captured stdout and stderr of the executed code.
_create_temp_file
Creates a temporary file with the given code and extension.
Parameters:
- code (str): The code to write to the temporary file.
- extension (str): The file extension to use.
Returns:
Path: The path to the created temporary file.
_check_code_type
supported_code_types
Provides supported code types by the interpreter.
update_action_space
Updates action space for python interpreter
_is_command_available
Check if a command is available in the system PATH.
Parameters:
- command (str): The command to check.
Returns:
bool: True if the command is available, False otherwise.