powershell - PowerShell Core 添加内容字节失败
问题描述
我正在使用 PowerShell Core v6.0.2,并尝试将字节数组写入文件。这在常规 PowerShell 中运行良好,但在 PowerShell Core 中失败
$jsonstr = Get-Content $inputfilename
$jsonfile = ConvertFrom-Json $jsonstr
$bytes = [Convert]::FromBase64String($jsonfile.data)
$outputfilename = "test.xlsx";
Add-Content -Path $outputfilename -Value $bytes -Encoding Byte
错误:
这是一个错误还是由于二进制排序问题而不能再使用 Byte ?
解决方案
根据这篇博文,在 PowerShell Core 上,您需要使用带有 AsByteStream 参数的 Set-Content 。
我已将脚本更改为以下内容:
$jsonstr = Get-Content $inputfilename
$jsonfile = ConvertFrom-Json $jsonstr
$bytes = [Convert]::FromBase64String($jsonfile.data)
$outputfilename = "test.xlsx";
Set-Content -Path $outputfilename -Value $bytes -AsByteStream
推荐阅读
- javascript - ReactJS passing input data to next screen/component
- java - Intellij unable to run test in IDE - Junit
- php - SOAP 调用 PHP 未发送所有参数
- android - 在顶部为 android 中的微调器数组添加标题
- transactions - 块处理模式下的 Spring Batch 事务回滚
- firebase - Firebase 存储:我应该删除 Firebase 存储中的工件文件吗?
- python - Openpyxl - 如何引用另一张纸上的单元格
- android - 我的 Android 应用程序数据库访问在模拟器中工作,但在生产中获取空值
- java - 后台服务崩溃
- java - 同步异步回调方法调用