Skip to content
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

Get-Content -Wait fails on WSL2 files #23964

Open
5 tasks done
Josephur opened this issue Jun 19, 2024 · 1 comment
Open
5 tasks done

Get-Content -Wait fails on WSL2 files #23964

Josephur opened this issue Jun 19, 2024 · 1 comment
Labels
Needs-Triage The issue is new and needs to be triaged by a work group.

Comments

@Josephur
Copy link

Prerequisites

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

@Josephur Josephur added the Needs-Triage The issue is new and needs to be triaged by a work group. label Jun 19, 2024
@rhubarb-geek-nz
Copy link

rhubarb-geek-nz commented Jun 21, 2024

Does Linux PowerShell running within WSL happily wait on the same file?

What file system type does the drive appear as to Windows?

Get-Content

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.

FileSystemContentStream.cs

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Triage The issue is new and needs to be triaged by a work group.
Projects
None yet
Development

No branches or pull requests

2 participants