8000 Call 'DoComplete' when handling FileRedirection for CommandExpression by daxian-dbw · Pull Request #4847 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 5 commits into from
Sep 20, 2017

Conversation

daxian-dbw
Copy link
Member

Fix #4812

Summary

When handling file redirection for CommandExpression, we don't call 'DoComplete' on the underlying PipelineProcessor of the FileRedirection object, and thus the EndProcessing method is not called on Out-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:

PS> 1 *> b.txt > a.txt; 123
Cannot perform operation because object "PipelineProcessor" has already been disposed

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

@daxian-dbw
Copy link
Member Author

@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.
Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Thanks!

Copy link
Contributor
@lzybkr lzybkr left a 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.

@daxian-dbw
Copy link
Member Author
daxian-dbw commented Sep 20, 2017

@lzybkr I opened the issue #4879 to tracking the effort to revisit the implementation of this method.

@lzybkr lzybkr merged commit 4c29f57 into PowerShell:master Sep 20, 2017
@daxian-dbw daxian-dbw deleted the redirect branch September 20, 2017 22:25
@vors vors removed their request for review September 25, 2017 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Direct redirection of a custom object ([pscustomobject] instance) to a file with ">" produces no output.
3 participants
0