如果我读取文件说使用Get-content占用了另一个进程,则工作正常。 但是,通过[IO.File] :: ReadAllText读取文件并显示错误消息: 该文件被另一个进程占用。
答案 0 :(得分:0)
这是两者之间的基本概念。
# returns array of lines in the file
Get-Content "FileName.txt"
# returns one string for whole file.
[System.IO.File]::ReadAllText("FileName.txt")
# There are ways to achieve second behavior with Get-Content, as of PowerShellv3 and later
Get-Content "FileName.txt" -Raw
# in PowerShell 2:
Get-Content "FileName.txt" | Out-String
详细信息在MS文档中。
Get-Content (Microsoft.PowerShell.Management)
您可以在MS PowerShell GitHub页面上查看Get-Content的源代码。 如果您真的想查看底层内容,或者可以使用Trace-Command查看在代码中使用它们时所采取的步骤。