-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Call 'DoComplete' when handling FileRedirection for CommandExpression #4847
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
Conversation
@lzybkr Can you please take a look when you have time? Thanks! |
// Expressions for this purpose are kept in 'extraFileRedirectExprs' and will be used later. | ||
extraFileRedirectExprs.Add(Expression.Call(redirectionExpr, CachedReflectionInfo.FileRedirection_CallDoCompleteForExpression)); | ||
|
||
// The 'UnBind' and 'Dispose' operations on 'FileRedirection' objects must be done in the reversed order of 'Bind' operations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in the reverse order
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code has always bothered me - it's more complicated than a redirected command.
I wonder how possible it would be to move most of this logic into a helper method and avoid generating so much complicated code.
Fix #4812
Summary
When handling file redirection for CommandExpression, we don't call 'DoComplete' on the underlying
PipelineProcessor
of theFileRedirection
object, and thus theEndProcessing
method is not called onOut-File
, which causes different behaviors between<expr> > out.txt
and<expr> | Out-File out.txt
.The fix is to make sure 'DoComplete' is called after the stream output has been written to the redirection pipe.
Also fix another issue
This PR also fixes an issue that could mess up restoring the original pipes. Here is the repro:
The root cause is that we don't always restore pipes in the correct order. Please see the code changes in
Compiler.cs
for more details./cc @mklement0