vscode: Terminal: add a way of getting the exit code

It would be great if each terminal object had an exitCode property that will resolve to the actual exit code of the process. Something like this:

Terminal {
  exitCode: Thenable<number> 
}

It would be especially useful when running commands in the terminal dynamically from extensions, this way we could easily detect when the terminal exited and if it the command exited without errors.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 7
  • Comments: 17 (14 by maintainers)

Commits related to this issue

Most upvoted comments

This will be available for testing in the first 1.41 insiders (probably 1-2 days away), let me know how it goes. FYI @eamodio

Proposal:

export interface Terminal {
  /**
   * The exit code of the terminal process, this will be undefined when the process was killed by
   * the user or no exit code was specified (for example when using CustomExecution).
   */
  readonly exitCode: Thenable<number | undefined>;
}

I’m not sure we would want a Thenable on the API for this as that’s what onDidCloseTerminal is for. Maybe this?

class Terminal {
  /**
   * The exit code of the terminal process, if the process has not yet
   * exited the value will be -1.
   */
  exitCode: number
}

I’ll bring it up in an upcoming API meeting so I can open this up to PRs.

(Experimental duplicate detection) Thanks for submitting this issue. Please also check if it is already covered by an existing one, like: