Polyman Documentation - v2.3.3
    Preparing search index...

    Class CommandExecutor

    Command executor for running external programs with resource constraints. Manages process lifecycle, timeout enforcement, memory limits, and cleanup. Supports cross-platform execution (Unix/Windows) with platform-specific tree-kill.

    CommandExecutor

    import { executor } from './executor';

    const result = await executor.execute('./solution', {
    timeout: 2000,
    memoryLimitMB: 256,
    silent: false
    });
    Index

    Constructors

    Properties

    tempFiles: string[] = []
    activeProcesses: Set<ExecaChildProcess<string>> = ...

    Methods

    • Execute a shell command with timeout and memory limits. Automatically kills the process tree if it exceeds time or memory constraints.

      Parameters

      • command: string

        Shell command to execute

      • options: ExecutionOptions

        Execution configuration

      Returns Promise<ExecutionResult>

      Execution result with stdout, stderr, and status

      If command fails and no onError callback is provided

      If timeout occurs and no onTimeout callback is provided

      If memory limit exceeded and no onMemoryExceeded callback is provided

    • Applies memory limit to a command using platform-specific methods. For Java programs, uses -Xmx flag. For Unix, wraps in a ulimit -v subshell. Windows memory limits are not enforced.

      Parameters

      • command: string
      • OptionalmemoryLimitMB: number

      Returns string

    • Normalizes command syntax for the current platform. On Windows, converts ./foo to .\foo and forward slashes in the executable path to backslashes to avoid ERROR_PATH_NOT_FOUND (3) from cmd.exe. Leaves arguments and redirections intact.

      Parameters

      • command: string

      Returns string

    • Detects if a process failed due to memory issues. Checks both exit codes (137, SIGABRT) and error messages in stderr.

      Parameters

      • code: number | null
      • signal: Signals | null
      • stderr: string

      Returns boolean

    • Kills a process and its entire child process tree. Uses taskkill /T /F on Windows, process-group SIGKILL on Unix. Falls back to single-process kill if the group call fails.

      Parameters

      • pid: number

      Returns void

    • Execute a command with input/output file redirection. Wraps the execute method with shell < / > redirections.

      Parameters

      • command: string
      • options: ExecutionOptions
      • OptionalinputFile: string
      • OptionaloutputFile: string

      Returns Promise<ExecutionResult>

    • Builds a shell command with input/output redirection. Quotes paths to survive spaces and normalizes them for the current platform.

      Parameters

      • command: string
      • OptionalinputFile: string
      • OptionaloutputFile: string

      Returns string

    • Register a temporary file for tracking.

      Parameters

      • filePath: string

      Returns void

    • Clean up all active processes and clear temp file registry. On Windows, waits briefly for file handles to be released.

      Returns Promise<void>

    • Get a copy of the registered temporary files list.

      Returns string[]