question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mklement0commented, Aug 8, 2017

@iSazonov:

I fear that that is not enough, because we would then need Bash-like job-control features, such as bringing a background job back to the foreground in case it needs interactive input (and “stopping” (suspending) it first if that happens in the background, and being able to send it back to the background.

Using PS jobs behind the scenes is not an option, because, as far as I know, there’s no support for jobs requesting interactive (non-redirected stdin) input.

Also, PS jobs don’t output directly to the invoking terminal the way Bash jobs do by default.

P.S.: I’ve updated the initial post to point out that Start-Process -Wait too is pointless on Unix.

0reactions
mklement0commented, Jul 15, 2018
Read more comments on GitHub >

github_iconTop Results From Across the Web

Start-Process (Microsoft.PowerShell.Management)
Specifies a file. This cmdlet sends the output generated by the process to a file that you specify. Enter the path and filename....
Read more >
Start-Process with PowerShell.exe exhibits different ...
(a) The initial parsing of the command line into arguments. (b) The subsequent evaluation of the resulting arguments following the -Command ( -c...
Read more >
about Environment Variables - PowerShell
Describes how to access and manage environment variables in PowerShell. Environment variables store data that's used by the operating system ...
Read more >
Types of shells supported by GitLab Runner
GitLab product documentation.
Read more >
Why is it better to use "#!/usr/bin/env NAME" instead of " ...
The disadvantage of #!/usr/bin/env python is that it will use whatever python executable appears first in the user's $PATH . That means that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found