1

I had tried to type File.jpg | ncat 192.168.0.2 3333 a file from Windows to Linux but the file was not the same. It was slightly larger and a hex editor showed most bytes were the same, with some changes and insertions scattered throughout.

I tried type C:\Path\File.jpg > C:\PathFile1.jpg and was surprised to obtain a file roughly twice the size of the original, with 00 inserted between the original file's hex values that mostly remained unaltered, with a few alterations and insertions.

I had executed those commands in Powershell. Then I tried the same commands using the old cmd.exe command prompt, and they worked!

This behavour is a surprise and I couldn't find any information on it. What's going on with Powershell?

alazyworkaholic
  • 537
  • 2
  • 8
  • 4
    In short: As of PowerShell 7.2, output from external programs is invariably decoded _as text_ before further processing, which means that _raw byte output_ can neither be passed on via `|` nor captured with `>`. See the [linked duplicate](https://stackoverflow.com/q/59110563/45375) for details. The workaround is to call your external program via `cmd /c` (Windows) / `sh -c` (Unix-like platforms) and use _their_ `|` and `>` operators. – mklement0 Dec 18 '21 at 23:16
  • 4
    P.S: `type` in PowerShell (on Windows) is a built-in alias of the [`Get-Content`](https://learn.microsoft.com/powershell/module/microsoft.powershell.management/get-content) cmdlet. – mklement0 Dec 18 '21 at 23:30

0 Answers0