Output binary data on PowerShell pipeline

后端 未结 4 1704
独厮守ぢ
独厮守ぢ 2021-02-13 20:05

I need to pipe some data to a program\'s stdin.

  1. First 4 bytes are a 32 bit unsigned integer representing the length of the data. These 4 bytes are exactly the sam
4条回答
  •  耶瑟儿~
    2021-02-13 21:02

    I need to pipe some data to a program's stdin.

    Many complex answers to this simple task. You can indeed cause many problems when using different encodings. Here is a different approach, without any encoding applied by Get-/Set-Content.

    You can actually pipe binary data to an external program by using the Start-Process cmdlet pretty easily:

    Start-Process my.exe -RedirectStandardInput my.bin
    

    Works at least since PowerShell 2.0.

提交回复
热议问题