-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
Credit to https://www.zhihu.com/question/1984199791559860674 (in Chinese).
First, prepare a directory with 1 file.
md PS-Wrong-Order;
cd PS-Wrong-Order;
'foobar' | Set-Content file.txt;Next, run the following lines of code:
# Line 1: The platform-native call is a statement.
Get-ChildItem | Select-Object Name; pwsh -command "Start-Sleep 1; 'hello'; '';"
# Line 2: Make the platform-native call a sub-expression.
Get-ChildItem | Select-Object Name; (pwsh -command "Start-Sleep 1; 'hello'; '';")
# Line 3: Add "Pause" function call in between for Line 1.
Get-ChildItem | Select-Object Name; Pause; pwsh -command "Start-Sleep 1; 'hello'; '';"; Pause;
# Line 4: Make intermediate call PowerShell-native instead of platform-native.
Get-ChildItem | Select-Object Name; Pause; Start-Sleep 1; 'hello'; ''; Pause;
# Line 5: Collecting piped data in Line 1, then output.
$data = &{ Get-ChildItem | Select-Object Name; pwsh -command "Start-Sleep 1; 'hello'; '';" }; $data;
# Line 6: Add "Out-Host" to first statement in Line 1.
Get-ChildItem | Select-Object Name | Out-Host; pwsh -command "Start-Sleep 1; 'hello'; '';"Importantly, each line must be pasted and run in its entirety. Do not split a line by its outer-level ; into multiple lines. Each line should be run separately. Do not paste multiple lines to be run in one shot. When prompted to press Enter to continue, press Enter.
Expected behavior
Line 1. The host prints 1 table-formatted object, waits for 1 second, then prints hello. The final state should be (ignore the number of blank lines, not to the point of this issue)
Name
----
file.txt
hello
Line 2. Same as Line 1.
Line 3. It should print 1 table-formatted object, asks to continue, waits for 1 second, outputs hello, asks to continue again. The final state should be
Name
----
file.txt
Press Enter to continue...:
hello
Press Enter to continue...:
Line 4. Same as Line 3.
Line 5. It should sleep for 1 second, then output the same thing as Line 1.
Line 6. Same as Line 1.
Actual behavior
Line 1. The host waits for 1 second, prints hello, then 1 table-formatted object. The order is wrong, and the wait is before the object.
hello
Name
----
file.txt
Line 2. It waits for 1 second, then output the things in the correct order.
Name
----
file.txt
hello
Line 3. It asks to continue, then pause for 1 second, then output hello, then asks to continue again, and finally outputs the object. The order is wrong, and the object is delayed.
Press Enter to continue...:
hello
Press Enter to continue...:
Name
----
file.txt
Line 4. It asks to continue, sleeps for 1 second, outputs the object, outputs hello, then asks to continue again. The object is delayed, but the order is correct now.
Press Enter to continue...:
Name
----
file.txt
hello
Press Enter to continue...:
Line 5. It is as expected --- sleeps for 1 second, then output everything in correct order.
Name
----
file.txt
hello
Line 6. It is as expected.
Name
----
file.txt
hello
Error details
Not applicable.
Environment data
Name Value
---- -----
PSVersion 7.5.4
PSEdition Core
GitCommitId 7.5.4
OS Microsoft Windows 10.0.26100
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals
Not applicable.