PrivatetempPrivateactiveExecute a shell command with timeout and memory limits. Automatically kills the process if it exceeds time or memory constraints.
Shell command to execute
Execution configuration
Execution result with stdout, stderr, and status
PrivateapplyPrivateApplies memory limit to a command using platform-specific methods. For Java programs, uses -Xmx flag. For Unix, uses ulimit. Windows memory limits are not fully supported.
Command to wrap with memory limit
OptionalmemoryLimitMB: numberMemory limit in megabytes
Command wrapped with memory limit enforcement
PrivatenormalizePrivateNormalizes command syntax for the current platform.
Command line string to normalize
Normalized command string appropriate for the platform
PrivatespawnPrivateSpawns a child process for command execution. Creates a detached process in shell mode to allow process tree management. Registers process in active processes set for cleanup tracking.
Shell command to spawn
Execution options including cwd
Spawned process and empty result object
PrivatecreatePrivateCreates an empty execution result object with default values. Used as initial state before process execution completes.
Empty result with default values
PrivatecreatePrivateCreates output collectors for stdout and stderr streams. Attaches data event handlers to accumulate process output. Tracks whether the result has been resolved to prevent race conditions.
Child process to collect output from
Output collectors object
PrivatecancellablePrivateCreates a cancellable delay promise for timeout implementation. Returns both the timeout promise and a cancel function. Cancel function clears the timeout to prevent unnecessary process kills.
Delay duration in milliseconds
Tuple of [timeout promise, cancel function]
PrivatehandlePrivateHandles timeout scenario when process exceeds time limit. Kills the process tree, updates result with timeout status, and invokes callbacks. Uses SIGKILL after grace period to ensure process termination.
Process that timed out
Execution options with timeout callback
Result object to update
Output collectors
Promise resolve function
Promise reject function
PrivateattachPrivateAttaches event handlers for process lifecycle events (close, error). Handles process completion, cleanup, and error scenarios. Ensures timeout is cancelled when process ends naturally.
Child process to attach handlers to
Execution options
Result object to populate
Output collectors
Function to cancel timeout
Promise resolve function
Promise reject function
PrivatehandlePrivateHandles process close event and determines outcome. Routes to appropriate handler based on exit code and signals. Checks for memory errors, success (code 0), or general errors.
Process exit code
Process termination signal
Execution options
Result object to populate
Output collectors
Promise resolve function
Promise reject function
PrivateisPrivateDetects if process failed due to memory issues. Checks both exit codes (137, SIGABRT) and error messages in stderr. Recognizes common memory error patterns across languages.
Process exit code
Process termination signal
Standard error output
True if memory error detected
PrivatehandlePrivateHandles memory limit exceeded scenario. Updates result with MLE status and invokes appropriate callback. Displays warning unless silent mode is enabled.
Process exit code
Process termination signal
Execution options with MLE callback
Result object to update
Promise resolve function
Promise reject function
PrivatehandlePrivateHandles successful process execution (exit code 0). Updates result status, displays output unless silent, and invokes success callback.
Execution options with success callback
Result object to update
Promise resolve function
PrivatehandlePrivateHandles failed process execution (non-zero exit code). Updates result status, displays error unless silent, and invokes error callback or rejects.
Execution options with error callback
Result object to update
Promise resolve function
Promise reject function
PrivatehandlePrivateHandles process spawn errors (e.g., command not found, permission denied). Updates result with error information and invokes error callback or rejects.
Error from process spawn
Execution options with error callback
Result object to update
Promise resolve function
Promise reject function
PrivatekillPrivateKills a process and its entire child process tree. Uses platform-specific methods: taskkill on Windows, process groups on Unix. Attempts to kill process group first, falls back to single process.
Process ID to kill
Execute a command with input/output file redirection. Wraps the execute method with automatic stdin/stdout redirection.
Shell command to execute
Execution configuration
OptionalinputFile: stringPath to file for stdin redirection (optional)
OptionaloutputFile: stringPath to file for stdout redirection (optional)
Execution result
PrivatebuildPrivateBuilds a shell command with input/output redirection. Appends stdin (<) and stdout (>) redirections as needed.
Base command to execute
OptionalinputFile: stringOptional input file path for stdin
OptionaloutputFile: stringOptional output file path for stdout
Command with redirection operators
Clean up all active processes and clear temp file registry. Kills any running processes and resets internal state. Should be called when shutting down or after batch operations. On Windows, waits for file handles to be released.
Resolves when cleanup is complete
Privatekill
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 optimizations.
CommandExecutor
Example