小编Fat*_*Hit的帖子

PowerShell - System.OutOfMemoryException

我想要Get-Content一个大(1GB - 10GB).txt文件(只有 1 行!)并将其拆分为多个包含多行的文件,但是每当我尝试时,我都会以System.OutOfMemoryException.

当然,我确实在寻找解决方案,但我找到的所有解决方案都是逐行读取文件,当文件只有 1 行时,这有点难以做到。

尽管 PowerShell 在加载 1 GB 文件时最多占用 4 GB RAM,但问题与我的 RAM 无关,因为我总共有 16 GB,即使在后台运行游戏,峰值使用率也约为 60%。

我将 Windows 10 与 PowerShell 5.1(64 位)一起使用,并且 myMaxMemoryPerShellMB设置为默认值2147483647.


这是我编写并正在使用的脚本,它适用于例如 100MB 的文件大小:

$source = "C:\Users\Env:USERNAME\Desktop\Test\"
$input = "test_1GB.txt"
$temp_dir = "_temp"

# 104'857'600 bytes (or characters) are exactly 100 MB, so a 1 GB file has exactly
# 10 temporary files, which have all the same size, and amount …
Run Code Online (Sandbox Code Playgroud)

powershell memory-error windows-10

4
推荐指数
1
解决办法
5736
查看次数

标签 统计

memory-error ×1

powershell ×1

windows-10 ×1