FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Call 'DoComplete' when handling FileRedirection for CommandExpression by daxian-dbw · Pull Request #4847 · PowerShell/PowerShell · GitHub

Call 'DoComplete' when handling FileRedirection for CommandExpression - #4847

Merged
Jason Shirk (lzybkr) merged 5 commits into
PowerShell:masterfrom
daxian-dbw:redirect
Sep 20, 2017
Merged

Call 'DoComplete' when handling FileRedirection for CommandExpression#4847
Jason Shirk (lzybkr) merged 5 commits into
PowerShell:masterfrom
daxian-dbw:redirect

Conversation

Copy link
Copy Markdown
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 Michael Klement (@mklement0)

Copy link
Copy Markdown
Member Author

Jason Shirk (@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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

done in the reverse order

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fixed. Thanks!

Jason Shirk (lzybkr) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Dongbo Wang (daxian-dbw) commented Sep 20, 2017
edited
Loading

Copy link
Copy Markdown
Member Author

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

Jason Shirk (lzybkr) merged commit 4c29f57 into PowerShell:master Sep 20, 2017
sergei (vors) removed their request for review September 25, 2017 00:34
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj/PowerShell that referenced this pull request Aug 6, 2026
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.

Fix PowerShell#4812
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL