Get-Content -Wait fails on WSL2 files
Prerequisites
- [X] Write a descriptive title.
- [X] Make sure you are able to repro it on the latest released version
- [X] Search the existing issues.
- [X] Refer to the FAQ.
- [X] Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
Map your WSL isntance to a drive letter. For instance my W: drive is mapped to \wsl$\Ubuntu
Run Get-Content with the -Path and -Wait parameter to print out the text file and monitor it for changes: Example: Get-Content -Path "W:\home\joseph\myvoipms\cron.log" -Wait
Expected behavior
Get-Content should wait for new content in the file, and print it as it comes in.
Actual behavior
Get-Content prints out the file, but then says "Get-Content: Incorrect function."
Error details
Exception :
Type : System.ComponentModel.Win32Exception
NativeErrorCode : 1
ErrorCode : -2147467259
TargetSite :
Name : WaitForChanges
DeclaringType : [Microsoft.PowerShell.Commands.FileSystemContentReaderWriter]
MemberType : Method
Module : System.Management.Automation.dll
Message : Incorrect function.
Source : System.Management.Automation
HResult : -2147467259
StackTrace :
at Microsoft.PowerShell.Commands.FileSystemContentReaderWriter.WaitForChanges(String filePath, FileMode fileMode,
FileAccess fileAccess, FileShare fileShare, Encoding fileEncoding)
at Microsoft.PowerShell.Commands.FileSystemContentReaderWriter.ReadByLine(Boolean waitChanges, List`1 blocks,
Boolean readBackward)
at Microsoft.PowerShell.Commands.FileSystemContentReaderWriter.Read(Int64 readCount)
at Microsoft.PowerShell.Commands.GetContentCommand.ProcessRecord()
CategoryInfo : InvalidOperation: (:) [Get-Content], Win32Exception
FullyQualifiedErrorId : ProviderContentReadError,Microsoft.PowerShell.Commands.GetContentCommand
InvocationInfo :
MyCommand : Get-Content
ScriptLineNumber : 1
OffsetInLine : 1
HistoryId : 3
Line : Get-Content -Path "W:\home\josephur\myvoipms\cron.log" -Wait
Statement : Get-Content -Path "W:\home\josephur\myvoipms\cron.log" -Wait
PositionMessage : At line:1 char:1
+ Get-Content -Path "W:\home\josephur\myvoipms\cron.log" -Wait
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InvocationName : Get-Content
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :
0
1
Environment data
Name Value
---- -----
PSVersion 7.4.3
PSEdition Core
GitCommitId 7.4.3
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
No response
Does Linux PowerShell running within WSL happily wait on the same file?
What file system type does the drive appear as to Windows?
Wait is a dynamic parameter that the FileSystem provider adds to the Get-Content cmdlet. This parameter works only in file system drives. Wait can't be combined with Raw.
WaitForChanges uses System.IO.FileSystemWatcher
Remote computers must have one of the required platforms installed for the component to function properly.
I don't see a list of required platforms for this function
Can you replace this with
wsl --user joseph tail -f myvoipms/cron.log
@Josephur does this still repro for you in latest Windows? Members of the cmdlet WG hasn't been able to repro this and works as expected
This issue still exists for me using the latest PowerShell 7.4.6
Get-Content should with the -Wait switch latch to the file and continue to read it, I wonder if it's something to do with the mapped drive to WSL perhaps?
Oh and to answer your question, if I install Powershell within my Ubuntu WSL, and use the same command on the same file, it works fine. It's only when Windows is using the mapped drive to access the Linux files when the error occurs.
Here's the details of the mapped drive:
C:\Users\Josephur>net use
New connections will be remembered.
Status Local Remote Network
-------------------------------------------------------------------------------
W: \\wsl$\Ubuntu Plan 9 Network Provider
This looks like an issue in the WSL file handler, I would suggest opening an issue in the WSL repo with a PowerShell 5.1 repro
This issue has been marked as external and has not had any activity for 1 day. It has been be closed for housekeeping purposes.
📣 Hey @Josephur, how did we do? We would love to hear your feedback with the link below! 🗣️
🔗 https://aka.ms/PSRepoFeedback