【问题标题】:PowerShell Get-Content cannot access the filePowerShell Get-Content 无法访问该文件
【发布时间】:2021-10-24 06:43:45
【问题描述】:

我有来自带有 windows 终端和命令的 wamp 服务器的监控日志

Get-Content "C:\wamp64\logs\php_error.log" -Wait

但由于某种原因,现在停止工作,我找不到问题所在。

当我启动 PowerShell 和命令时,我可以看到 php_error.log 的内容,但是当 wamp 开始在 php_error.log 中写入/追加新内容时,我有这个错误

Get-Content : The process cannot access the file because another process has locked a portion of the file.
At line:1 char:1
+ Get-Content "C:\wamp64\logs\php_error.log" -Wait
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ReadError: (C:\wamp64\logs\php_error.log:String) [Get-Content], IOException
    + FullyQualifiedErrorId : GetContentReaderIOError,Microsoft.PowerShell.Commands.GetContentCommand

【问题讨论】:

  • 关闭 WinAmp,它应该可以正常工作。
  • 不是 Winamp,是 Wamp 服务器
  • 因为制作文件的应用程序已锁定文件......你被困住了。要么将调用包装在 try-catch 块中,要么使用其他错误处理方法。

标签: powershell wamp


【解决方案1】:

Get-Content 在读取时尝试锁定文件,但由于文件已被锁定而未能锁定。解决方案是使用另一种方法,让您指定读取该文件的方式和访问权限。看看this answer here

【讨论】:

    猜你喜欢
    • 2014-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-11
    • 2016-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多