Skip to content

Clarify the purpose / behavior of the Start-Process cmdlet on Unix platforms #4521

@mklement0

Description

@mklement0

On Windows, the default behavior of Start-Process is to run a program in a new window, asynchronously.
Console applications can optionally be forced to run in the current console (terminal) with -NoNewWindow, but that is of limited usefulness.

On Unix (Linux and macOS), as of PowerShell Core v6.0.0-beta.5, -NoNewWindow is the implied and unchangeable default: terminal (console) programs invariably execute in the current terminal, which is rarely useful:
A program asking for interactive input interferes with the current shell and/or one producing (non-redirected) output prints it asynchronously to the current terminal, which can be disruptive - see #1543.

For non-interactive terminal programs, launching a job, e.g., by simply appending & - is the superior alternative, given that it allows you to determine success and inspect the output later.

For synchronous invocations, using -Wait is also pointless on Unix:

  • To run a terminal-based application synchronously, just invoke it directly - no need for Start-Process

  • -Wait is not effective with a GUI-launching CLI such as code for Visual Studio Code, which launches the GUI asynchronously, but in a manner that Start-Process doesn't detect.

This leaves just the following narrow use cases for Start-Process on Unix:

  • Launching a terminal-based application asynchronously, assuming that that application doesn't request interactive user input (something that is supported in Bash - see below) and ideally doesn't produce (non-redirected) stdout/stderr output, as that would print asynchronously in the current terminal.
  • Launching a GUI application whose CLI is blocking - e.g., gedit - in a non-blocking manner:
    Start-Process gedit, as a light-weight, launch-it-and-forget-it alternative to gedit & (which invariably creates a job).

Is the current Start-Process behavior what is intended for the v6 release on Unix?

If so:

  • The documentation should clearly state its limitations.
  • Perhaps runtime warnings for pointless invocations can be implemented.

As an aside: On Windows, Start-Process can also open documents, whereas on Unix only Invoke-Item can do that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Committee-ReviewedPS-Committee has reviewed this and made a decisionIssue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-AnsweredThe question is answered.WG-Cmdlets-Managementcmdlets in the Microsoft.PowerShell.Management module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions