Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7.4.0 Start-Process with -PassThru & -RedirectStandardOutput does not return the process object completely ( properties like Exitcode ) #20716

Closed
5 tasks done
derkveenhof opened this issue Nov 17, 2023 · 10 comments
Labels
Needs-Triage The issue is new and needs to be triaged by a work group. Resolution-Fixed The issue is fixed.

Comments

@derkveenhof
Copy link

derkveenhof commented Nov 17, 2023

Prerequisites

Steps to reproduce

When i use Start-Process with -PassThru & -RedirectStandardOutput , the process object is not returned completely. This has been since 7.4.0

Expected behavior

This was the 7.3.9 behavior:

PS C:\Users\thiscouldbeme> $Process = start-process notepad -PassThru -wait -RedirectStandardOutput c:\temp\sa.txt
PS C:\Users\thiscouldbeme> $Process | Select *

Name                       :
Id                         : 33776
PriorityClass              :
FileVersion                :
HandleCount                :
WorkingSet                 :
PagedMemorySize            :
PrivateMemorySize          :
VirtualMemorySize          :
TotalProcessorTime         : 00:00:00
SI                         :
Handles                    :
VM                         :
WS                         :
PM                         :
NPM                        :
Path                       :
CommandLine                :
Parent                     : System.Diagnostics.Process (pwsh)
Company                    :
CPU                        : 0
ProductVersion             :
Description                :
Product                    :
__NounName                 : Process
SafeHandle                 : Microsoft.Win32.SafeHandles.SafeProcessHandle
Handle                     : 2500
BasePriority               :
ExitCode                   : 0
HasExited                  : True
StartTime                  : 17-11-2023 18:31:48
ExitTime                   : 17-11-2023 18:31:50
MachineName                : .
MaxWorkingSet              :
MinWorkingSet              :
Modules                    :
NonpagedSystemMemorySize64 :
NonpagedSystemMemorySize   :
PagedMemorySize64          :
PagedSystemMemorySize64    :
PagedSystemMemorySize      :
PeakPagedMemorySize64      :
PeakPagedMemorySize        :
PeakWorkingSet64           :
PeakWorkingSet             :
PeakVirtualMemorySize64    :
PeakVirtualMemorySize      :
PriorityBoostEnabled       :
PrivateMemorySize64        :
ProcessorAffinity          :
SessionId                  :
StartInfo                  :
Threads                    :
VirtualMemorySize64        :
EnableRaisingEvents        : False
StandardInput              :
StandardOutput             :
StandardError              :
WorkingSet64               :
SynchronizingObject        :
MainModule                 :
PrivilegedProcessorTime    : 00:00:00
UserProcessorTime          : 00:00:00
ProcessName                :
MainWindowHandle           : 0
MainWindowTitle            :
Responding                 : True
Site                       :
Container                  :

Actual behavior

PS C:\Windows\System32> $Process = start-process notepad -PassThru -wait -RedirectStandardOutput c:\temp\sa.txt
PS C:\Windows\System32> $Process | Select *

Name                       :
Id                         : 3264
PriorityClass              :
FileVersion                :
HandleCount                :
WorkingSet                 :
PagedMemorySize            :
PrivateMemorySize          :
VirtualMemorySize          :
TotalProcessorTime         :
SI                         :
Handles                    :
VM                         :
WS                         :
PM                         :
NPM                        :
Path                       :
CommandLine                :
Parent                     :
Company                    :
CPU                        :
ProductVersion             :
Description                :
Product                    :
__NounName                 : Process
SafeHandle                 :
Handle                     :
BasePriority               :
ExitCode                   :
HasExited                  : True
StartTime                  :
ExitTime                   :
MachineName                : .
MaxWorkingSet              :
MinWorkingSet              :
Modules                    :
NonpagedSystemMemorySize64 :
NonpagedSystemMemorySize   :
PagedMemorySize64          :
PagedSystemMemorySize64    :
PagedSystemMemorySize      :
PeakPagedMemorySize64      :
PeakPagedMemorySize        :
PeakWorkingSet64           :
PeakWorkingSet             :
PeakVirtualMemorySize64    :
PeakVirtualMemorySize      :
PriorityBoostEnabled       :
PrivateMemorySize64        :
ProcessorAffinity          :
SessionId                  :
StartInfo                  :
Threads                    :
VirtualMemorySize64        :
EnableRaisingEvents        : False
StandardInput              :
StandardOutput             :
StandardError              :
WorkingSet64               :
SynchronizingObject        :
MainModule                 :
PrivilegedProcessorTime    :
UserProcessorTime          :
ProcessName                :
MainWindowHandle           : 0
MainWindowTitle            :
Responding                 : True
Site                       :
Container                  :

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.0
PSEdition                      Core
GitCommitId                    7.4.0
OS                             Microsoft Windows 10.0.20348
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

@derkveenhof derkveenhof added the Needs-Triage The issue is new and needs to be triaged by a work group. label Nov 17, 2023
@derkveenhof derkveenhof changed the title 7.4.0 Start-Process with -PassThru & -RedirectStandardOutput does not return the process object ( properties like Exitcode ) 7.4.0 Start-Process with -PassThru & -RedirectStandardOutput does not return the process object completely ( properties like Exitcode ) Nov 17, 2023
@mklement0
Copy link
Contributor

Good find, but it is a duplicate of:

See also:

In light of the recently introduced bot action of closing old posts that haven't had activity in a while, it may be worth keeping this one open, however.

@derkveenhof
Copy link
Author

derkveenhof commented Nov 19, 2023

Caching the Handle seems to work.

This workaround works:
$Process = Start-Process Notepad -PassThru -RedirectStandardOutput c:\temp\sa.txt
$Handle = $Process.Handle
$Process.WaitForExit()
$Process | Select *

I left -Wait away. Cached the handle and then using the System.Diagnostics.Prccess WaitOfExit method.

Name :
Id : 56656
PriorityClass :
FileVersion :
HandleCount :
WorkingSet :
PagedMemorySize :
PrivateMemorySize :
VirtualMemorySize :
TotalProcessorTime : 00:00:00
SI :
Handles :
VM :
WS :
PM :
NPM :
Path :
CommandLine :
Parent : System.Diagnostics.Process (pwsh)
Company :
CPU : 0
ProductVersion :
Description :
Product :
__NounName : Process
SafeHandle : Microsoft.Win32.SafeHandles.SafeProcessHandle
Handle : 4760
BasePriority :
ExitCode : 0
HasExited : True
StartTime : 19-11-2023 21:28:02
ExitTime : 19-11-2023 21:28:03
MachineName : .
MaxWorkingSet :
MinWorkingSet :
Modules :
NonpagedSystemMemorySize64 :
NonpagedSystemMemorySize :
PagedMemorySize64 :
PagedSystemMemorySize64 :
PagedSystemMemorySize :
PeakPagedMemorySize64 :
PeakPagedMemorySize :
PeakWorkingSet64 :
PeakWorkingSet :
PeakVirtualMemorySize64 :
PeakVirtualMemorySize :
PriorityBoostEnabled :
PrivateMemorySize64 :
ProcessorAffinity :
SessionId :
StartInfo :
Threads :
VirtualMemorySize64 :
EnableRaisingEvents : False
StandardInput :
StandardOutput :
StandardError :
WorkingSet64 :
SynchronizingObject :
MainModule :
PrivilegedProcessorTime : 00:00:00
UserProcessorTime : 00:00:00
ProcessName :
MainWindowHandle : 0
MainWindowTitle :
Responding : True
Site :
Container :

@mklement0
Copy link
Contributor

mklement0 commented Nov 20, 2023

Good to know a workaround.

Just to spell it out: it won't work if -Wait is used (as in #20400), and while switching to a separate .WaitForExit() / Wait-Process call does allow you to use the workaround, it isn't a fully equivalent solution - though in practice it will often suffice. See:

@stephen9357
Copy link

I faced the same problem, thanks for your workaround @derkveenhof

@MarkDordoy
Copy link

Can also confirm I've seen the same issue.

@astrahan87
Copy link

+1

@AFAde
Copy link

AFAde commented Dec 13, 2023

Same issue here, please provide a fix

@mklement0
Copy link
Contributor

@SteveL-MSFT SteveL-MSFT added KeepOpen The bot will ignore these and not auto-close WG-NeedsReview Needs a review by the labeled Working Group Resolution-Fixed The issue is fixed. and removed WG-NeedsReview Needs a review by the labeled Working Group KeepOpen The bot will ignore these and not auto-close labels Apr 29, 2024
Copy link
Contributor

This issue has been marked as fixed and has not had any activity for 1 day. It has been closed for housekeeping purposes.

Copy link
Contributor

microsoft-github-policy-service bot commented May 1, 2024

📣 Hey @derkveenhof, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 https://aka.ms/PSRepoFeedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Triage The issue is new and needs to be triaged by a work group. Resolution-Fixed The issue is fixed.
Projects
None yet
Development

No branches or pull requests

7 participants