Skip to content

io microsphere process ProcessExecutor

github-actions[bot] edited this page Mar 21, 2026 · 1 revision

ProcessExecutor

Type: Class | Module: microsphere-java-core | Package: io.microsphere.process | Since: 1.0.0

Source: microsphere-java-core/src/main/java/io/microsphere/process/ProcessExecutor.java

Overview

Process Executor

Executes operating system commands and manages the execution lifecycle, including handling input/output streams, monitoring process status, and enforcing timeouts. This class wraps command execution in a structured way to provide enhanced control and integration with the framework.

Example Usage

    // Execute a simple command with options and capture output
    ProcessExecutor executor = new ProcessExecutor("ls", "-l", "/home");
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    executor.execute(outputStream);
    System.out.println("Command Output: " + outputStream.toString());

    // Execute a command with timeout protection
    try {
        executor.execute(outputStream, 5000); // 5 seconds timeout
    } catch (TimeoutException e) {
        System.err.println("Command timed out!");
    }

Declaration

public class ProcessExecutor

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.1.10-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 8 ✅ Compatible
Java 11 ✅ Compatible
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

// Execute a simple command with options and capture output
    ProcessExecutor executor = new ProcessExecutor("ls", "-l", "/home");
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    executor.execute(outputStream);
    System.out.println("Command Output: " + outputStream.toString());

    // Execute a command with timeout protection
    try {
        executor.execute(outputStream, 5000); // 5 seconds timeout
    } catch (TimeoutException e) {
        System.err.println("Command timed out!");
    }

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-java-core</artifactId>
    <version>${microsphere-java.version}</version>
</dependency>

Tip: Use the BOM (microsphere-java-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.process.ProcessExecutor;

API Reference

Public Methods

Method Description
execute The default proeprty value for the timeout of process execution : 30 seconds
execute Execute current process.
execute Execute current process.

Method Details

execute

public void execute(OutputStream outputStream)

The default proeprty value for the timeout of process execution : 30 seconds / public static final String DEFAULT_PROCESS_EXECUTION_TIMEOUT_PROPERTY_VAUE = "30000";

/** The default value for the timeout of process execution : 30 seconds / public static final long DEFAULT_PROCESS_EXECUTION_TIMEOUT = parseLong(DEFAULT_PROCESS_EXECUTION_TIMEOUT_PROPERTY_VAUE);

/** The property name for the timeout of process execution : "process.execution.timeout"

See Also

  • ProcessManager

This documentation was auto-generated from the source code of microsphere-java.

Home

java-annotations

java-core

jdk-tools

lang-model

annotation-processor

java-test

Clone this wiki locally