Interface StdoutRedirectGuard

The class guarding the stdout redirect. Keep this instance in scope to not lose the redirect. As soon as this gets garbage collected, the redirection of the stdout/stderr will be stopped. Only one instance of this can exist at a time. Call reset to stop redirecting the program output and release this class instance early.

This can be created by calling stdout.enableRedirect.

Example

import { stdout } from 'java-bridge';

const guard = stdout.enableRedirect((_, data) => {
console.log('Stdout:', data);
}, (_, data) => {
console.error('Stderr:', data);
});

// Change the receiver method
guard.on('stderr', (_, data) => {
console.warn('Stderr:', data);
});

// Disable a receiver
guard.on('stdout', null);

// Disable stdout redirect
guard.reset();

See also

interface StdoutRedirectGuard {
    on(event, callback): void;
    reset(): void;
}

Methods

Methods

  • Set the stdout/stderr event handler. Pass null to disable this specific handler. Only accepts 'stdout' and 'stderr' as the event argument. Overwrites the previous handler.

    Parameters

    • event: "stdout" | "stderr"

      the event to listen on

    • callback: null | StdoutCallback

      the callback

    Returns void

  • Reset this StdoutRedirectGuard instance. After this call, the stdout/stderr will no longer be redirected to the specified methods and any call to this class will throw an error as this counts as destroyed.

    Returns void

Generated using TypeDoc