我想将命令的输出通过管道传输到文件:
PS C:\Temp> create-png > binary.png
Run Code Online (Sandbox Code Playgroud)
我注意到 Powershell 更改了编码,并且我可以手动给出编码:
PS C:\Temp> create-png | Out-File "binary.png" -Encoding OEM
Run Code Online (Sandbox Code Playgroud)
然而,没有 RAW 编码选项,即使 OEM 选项也会将换行字节 ( 0xAresp 0xD) 更改为 Windows 换行字节序列 ( 0xD 0xA),从而破坏任何二进制格式。
如何防止 Powershell 在管道传输到文件时更改编码?
相关问题
我发现一个示例在 Windows 中无法正常工作。该程序演示了 Go 标准图像包的基本用法,我们将使用它来创建位图图像序列,然后将该序列编码为 GIF 动画。
package main
import (
"image"
"image/color"
"image/gif"
"io"
"math"
"math/rand"
"os"
)
import (
"log"
"net/http"
"time"
)
//!+main
var palette = []color.Color{color.White, color.Black}
const (
whiteIndex = 0 // first color in palette
blackIndex = 1 // next color in palette
)
func main() {
//!-main
// The sequence of images is deterministic unless we seed
// the pseudo-random number generator using the current time.
// Thanks to Randall McPherson for pointing …Run Code Online (Sandbox Code Playgroud)