Function enableRedirect

  • Enable stdout/stderr redirection.

    Pass methods for the stdout and stderr output to be redirected to. These methods must accept an error as the first argument, although this will probably never be set and can be ignored. The second argument is the data that was redirected.

    Setting any method to null or undefined will disable the redirect for that method. This also allows you not set any handler which does not make any sense at all.

    Examples

    Redirect all data to the js console

    import { stdout } from 'java-bridge';

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

    Redirect stdout to the js console

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

    Redirect stderr to the js console

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

    Redirect nothing to the js console (y tho)

    This enables you to print nothing to nowhere.

    // Why would you do this?
    const guard = stdout.enableRedirect(null, null);

    // Or
    const guard = stdout.enableRedirect();

    Parameters

    • Optional stdout: null | StdoutCallback

      the callback to be called when stdout is received

    • Optional stderr: null | StdoutCallback

      the callback to be called when stderr is received

    Returns StdoutRedirectGuard

    a StdoutRedirectGuard instance. Keep this instance in scope to not lose the redirect.

    See

    • StdoutRedirectGuard
    • StdoutCallback

Generated using TypeDoc