5

I am running a Go program that generates a file in gif format. When using Bash or Command Prompt, the file is generated successfully. However, when using PowerShell or PowerShell-Core, I receive an error: "The image ‘file:///C:\Users\blah\blah\blah’ cannot be displayed because it contains errors".

How can I generate this file correctly using PowerShell?

I have attempted to run the exact same commands that worked on Bash and Command Prompt. I have also tried using PowerShell cmdlets like Out-File and Tee-Object.

go build main.go
.\main.exe > out.gif
firefox out.gif

Performing the above actions in Bash or Command Prompt generate the file and the expected gif. Performing the action in PowerShell yields the error message described above (image cannot be displayed because it contains errors).

I have also tried:

.\main.exe | Out-File out.gif
and
.\main.exe | Tee-Object out.gif

Both generate the broken file.

csk
  • 61
  • 2
  • Write directly to a file, as can be seen in the marked duplicate. PowerShell converts certain control characters. – icza Jun 03 '19 at 12:36
  • A potentially better duplicate is [this](https://stackoverflow.com/q/28166845/4137916). The general issue really has nothing to do with `go` or image files; it's about PowerShell and binary output. It is, of course, possible to write a file in `go` instead, but if you can't or don't want to modify the `go` program you'll have to solve it on the PowerShell end. – Jeroen Mostert Jun 03 '19 at 12:39
  • Interesting, thanks! Perhaps I'll just stick to doing it in CMD or in a Linux operating system. Very bizarre. – csk Jun 03 '19 at 12:43
  • 1
    Lol should I delete the question? None of those results came up when I was looking for my question. And generally when I search for something it points to StackOverflow marking something as duplicate anyway, which has helped me and I'm assuming has helped others. If I don't get -10 I'll be disappointed in everything I've heard about this community. – csk Jun 03 '19 at 12:48
  • Up to you. If you couldn't find the other ansers, maybe others won't be able too, and this question might still help them. – icza Jun 03 '19 at 12:54
  • SO's own search is legendarily useless when it comes to finding actual duplicate questions; you're better off using a general search engine with a restriction like `site:stackoverflow.com`. – Jeroen Mostert Jun 03 '19 at 12:56
  • 2
    Don't delete the question, it will help others find the answer, I'm sure you won't be the only one who doesn't find it in a search – thatjeffsmith Jun 03 '19 at 13:08

0 Answers0