Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Shell

Shell class. Created new instance by createShell.

Hierarchy

  • EventEmitter
    • Shell

Index

Events

on

  • Event emitted when shell's standard output or standard error has new data. type parameter is used to distinguish standard output and standard error.

    Parameters

    Returns Shell

  • Event emitted when shell's standard output or standard error has new line. type parameter is used to distinguish standard output and standard error.

    Parameters

    Returns Shell

Methods

addListener

  • addListener(event: string | symbol, listener: (...args: any[]) => void): Shell
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Shell

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

eventNames

  • eventNames(): (string | symbol)[]
  • Returns (string | symbol)[]

exec

  • Execute a shell command and wait for the result asynchronously.

    example
    "nodejs";
    const { createShell } = require('shell');
    async function main() {
        const shell = createShell();
        console.log(await shell.exec("touch test.txt"));
        console.log(await shell.exec("ls -l test.txt"));
        await shell.exit();
    }
    main();
    

    Parameters

    • cmd: string

      Shell command to execute

    Returns Promise<ExecutionResult>

    Promise of the execution result

exit

  • Exit the shell process. If forcedly is true, the process will be terminated and the return value will be a string representing the signal that killed the process. If forcedly is false, the process will be terminated by exit command and the return value will be the exit code.

    Parameters

    • Optional forcedly: boolean

    Returns Promise<ExitResult>

getMaxListeners

  • getMaxListeners(): number
  • Returns number

listenerCount

  • listenerCount(event: string | symbol): number
  • Parameters

    • event: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

off

  • off(event: string | symbol, listener: (...args: any[]) => void): Shell
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Shell

once

  • once(event: string | symbol, listener: (...args: any[]) => void): Shell
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Shell

prependListener

  • prependListener(event: string | symbol, listener: (...args: any[]) => void): Shell
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Shell

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): Shell
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Shell

rawListeners

  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

removeAllListeners

  • removeAllListeners(event?: string | symbol): Shell
  • Parameters

    • Optional event: string | symbol

    Returns Shell

removeListener

  • removeListener(event: string | symbol, listener: (...args: any[]) => void): Shell
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Shell

setMaxListeners

  • setMaxListeners(n: number): Shell
  • Parameters

    • n: number

    Returns Shell

submit

  • submit(input: string): void
  • Submit text to shell's standard input. If the text does not end with a newline character, a newline character will be appended automatically.

    Parameters

    • input: string

    Returns void