Skip to content

Start-Process -NoNewWindow broken in core edition #1543

Closed

Description

@vors

Steps to reproduce

Start-Process -NoNewWindow powershell

Expected behavior

Run process in a new window

Actual behavior

Run process in the same window, but UX is broken

PS /Users/vors> Start-Process -NoNewWindow powershell                                                                                        
PS /Users/vors> 14;1Rl                                                                                                                       
14pyright (C) 2016 Microsoft Corporation. All rights reserved.
1Rl : The term '1Rl' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, 
or if a path was included, verify that the path is correct and try again.
At line:1 char:4
+ 14;1Rl
+    ~~~
    + CategoryInfo          : ObjectNotFound: (1Rl:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS /Users/vors>                 ^Dlssaad  

Environment data

Repros on OS X, Linux and Windows

> $PSVersionTable

Name                           Value                                                                                                        
----                           -----                                                                                                        
PSVersion                      5.1.10032.0                                                                                                  
PSEdition                      PowerShellCore                                                                                               
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                      
BuildVersion                   3.0.0.0                                                                                                      
GitCommitId                    v6.0.0-alpha.7                                                                                               
CLRVersion                                                                                                                                  
WSManStackVersion              3.0                                                                                                          
PSRemotingProtocolVersion      2.3                                                                                                          
SerializationVersion           1.1.0.1  

Activity

  1. modified the milestone: on Aug 4, 2016
  2. added
    Up-for-Grabs
    on Sep 20, 2016
  3. 0xfeeddeadbeef commented on Apr 13, 2017

    @0xfeeddeadbeef
    Contributor

    sergei (@vors) Expected behavior is not quite correct. According to Get-Help Start-Process:

    -NoNewWindow [<SwitchParameter>]
        Start the new process in the current console window. By default Windows PowerShell opens a new window.
    

    it should start in the current console window.

    However, UX being broken is still true, - it seems that both parent and child powershell.exe processes are competing for user input. This is my attempt to type $PSVersionTable:

    PS C:\Users\Giorgi.Chakhidze> Start-Process -NoNewWindow powershell.exe
    PS C:\Users\Giorgi.Chakhidze> $SesoTal
    Copyright (C) 2016 Microsoft Corporation. All rights reserved.
    
    PS C:\Users\Giorgi.Chakhidze>
    $ PVrinbe
    
  4. joeyaiello commented on May 23, 2017

    @joeyaiello
    Contributor

    Yeah, can confirm this is still broken.

  5. florinciubotariu commented on Aug 2, 2017

    @florinciubotariu

    Can confirm it is still reproducible.

  6. mklement0 commented on Aug 7, 2017

    @mklement0
    Contributor

    Definitely broken, but It is worth noting that Start-Process -NoNewWindow powershell doesn't make much sense, given that it amounts to running an interactive shell asynchronously in the current terminal (which results in two shells competing for input, as Giorgi Chakhidze (@0xfeeddeadbeef)'s experience suggests).

    Adding -Wait - Start-Process -Wait -NoNewWindow powershell - works properly, but there's no good reason to use it, given that just invoking powershell directly is not only simpler (it implicitly runs synchronously in the current terminal), but is also properly integrated with the current session's input/output streams, unlike a Start-Process call.

    -NoNewWindow is really only useful in very limited circumstances:

    • for console applications (GUI applications open their own (non-console) window anyway)
    • that produce no output / whose output is redirected via -RedirectStandardOutput / -RedirectStandardError

    It is a poor substitute for using a job to launch a console application in the background, which gives you much better control.

    Unless I'm missing other use cases for -NoNewWindow, it may be a candidate for deprecation.

  7. vors commented on Aug 7, 2017

    @vors
    CollaboratorAuthor

    True, counting the number of negatives is hard :D
    If I recall correctly, the reason I opened the issue is the there is mismatch in behavior and on core powershell it's implicit NoNewWindow.

  8. mklement0 commented on Aug 7, 2017

    @mklement0
    Contributor

    sergei (@vors): It may be time to decide the fate / behavior of Start-Process on Unix platforms: please see #4521.

  9. vors commented on Feb 20, 2018

    @vors
    CollaboratorAuthor

    How about making NoNewWindow a no-op on unix?

  10. 12 remaining items

  11. mklement0 commented on Dec 6, 2018

    @mklement0
    Contributor

    There is no reason to involve Start-Process at all if you want to run a console/terminal-based application synchronously: not only is direct invocation simpler, only the latter guarantees that the invoked program's output streams are connected to PowerShell's.

    Start-Process is asynchronous by default; that's what the standard verb in its name implies, and I don't think there should be any exceptions, especially not for use cases that make no sense to begin with.

    -NoNewWindow in effect is a no-op on Unix-like platforms, and it makes sense to document it as such.

    Yes, that means that someone can shoot themselves in the foot with something like Start-Process [-NoNewWindow] bash on Unix, but to me that's still preferable to special-casing behavior.
    Sensible use cases for Start-Process on Unix are very limited compared to Windows; I've tried to summarize them here - integration into the docs is pending.

  12. SteveL-MSFT commented on Dec 19, 2018

    @SteveL-MSFT
    Member

    Michael Klement (@mklement0) I agree that Start implies async and also agree that -NoNewWindow doesn't make sense on Unix-like platforms. However, it doesn't make sense to continue to allow users to get into this situation. However, I don't see this as a priority to fix as I don't believe it affects a large number of users and I expect they'll learn quickly not to use it again after the first time.

  13. added
    Up-for-Grabs
    on Dec 19, 2018
  14. mklement0 commented on Dec 19, 2018

    @mklement0
    Contributor

    Steve Lee (@SteveL-MSFT):

    I expect they'll learn quickly not to use it again after the first time.

    Yes, which is why I think the problem can be dealt with by simply providing proper guidance in the Start-Process help topic (update: see MicrosoftDocs/PowerShell-Docs#3013):

    • By stating in the Description section that -NoNewWindow is invariably implied on Unix-like platforms.

    • By stating in the description of parameter -NoNewWindow:

      • that (possibly implied) -NoNewWindow is only relevant to console/terminal-based applications and generally only makes sense in very limited circumstances (to put it differently: typically, there's no need to use Start-Process to invoke console/terminal-based programs):

        • Launch-it-and-forget-it console/terminal-based commands known not to produce output / expect interactive input (if the target program is not console/terminal-based, there's no reason to use -NoNewWindow to begin with),

        • Console/terminal-based commands that require running with a pristine environment with -UseNewEnvironment; if such commands happen to produce output / require interactive input, then -Wait must used, too. (On Windows, if the process with a pristine environment should run in a new window anyway, there's obviously no need for -NoNewWindow.)

      • that not also including -Wait for console/terminal-based application will cause them to send output asynchronously / compete for interactive input with the calling session.

  15. red8888 commented on Jun 19, 2020

    @red8888

    when using -NoNewWindow I get this error: This command cannot be run due to the error: %1 is not a valid Win32 application.

  16. BouwenMA commented on Jul 2, 2020

    @BouwenMA

    I've come across issues with this today wondering why my Start-Process with -NoNewWindow parameter was seeming to hang until I pressed enter...

    As Michael Klement (@mklement0) stated above, I agree that the help topic should be updated. After spending a bit of time with several searches and articles trying to figure out the problem, I finally came across this issue... Noting that one should use "-Wait", or altering the behavior of -NoNewWindow to implicitly wait, would seem to be very helpful. Had it been in the contents of the Start-Process help, I would've known immediately...

    For my use case, I've been using Start-Process for running PSExec with various parameters, as I cycle through pushing updates to many servers. But for simplicy, the behavior I'm seeing can be reproduced on all PowerShell versions 5-7.1 I've tried so far like this:

    Start-Process -FilePath IPConfig -NoNewWindow
    

    The output will be shown, with the cursor just sitting at the bottom flashing, and only bring back the prompt after I hit enter or up arrow... As long as I append "-Wait" it behaves as desired...

  17. mklement0 commented on Jul 2, 2020

    @mklement0
    Contributor

    Thanks, Mathias (@BouwenMA).

    Note the pending issue requesting updating of the docs (it's been open since December 2018): MicrosoftDocs/PowerShell-Docs#3013 - if you're up for it, you could try to submit a PR yourself.

    Also - in case ipconfig.exe wasn't just a random example - remember that there's generally no good reason to use Start-Process with console applications such as ipconfig.exe (or psexec), as explained above and as also covered in the linked issue.

  18. doctordns commented on Feb 15, 2022

    @doctordns
    Collaborator

    Trying this in 7.2.1 - the UX is still broken.

  19. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  20. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  21. added
    Resolution-No Activity
    on Nov 16, 2023
  22. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  23. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Committee-ReviewedIssue-BugOS-LinuxOS-WindowsOS-macOSResolution-No ActivityUp-for-GrabsWG-CmdletsWG-Interactive-Console

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions