PowerShell - Start-Process and Cmdline Switches

前端 未结 5 641
我寻月下人不归
我寻月下人不归 2020-11-28 08:27

I can run this fine:

$msbuild = \"C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.5\\MSBuild.exe\" 
start-process $msbuild -wait

But when I run t

5条回答
  •  猫巷女王i
    2020-11-28 08:59

    Warning

    If you run PowerShell from a cmd.exe window created by Powershell, the 2nd instance no longer waits for jobs to complete.

    cmd>  PowerShell
    PS> Start-Process cmd.exe -Wait 
    

    Now from the new cmd window, run PowerShell again and within it start a 2nd cmd window: cmd2> PowerShell

    PS> Start-Process cmd.exe -Wait
    PS>   
    

    The 2nd instance of PowerShell no longer honors the -Wait request and ALL background process/jobs return 'Completed' status even thou they are still running !

    I discovered this when my C# Explorer program is used to open a cmd.exe window and PS is run from that window, it also ignores the -Wait request. It appears that any PowerShell which is a 'win32 job' of cmd.exe fails to honor the wait request.

    I ran into this with PowerShell version 3.0 on windows 7/x64

提交回复
热议问题