简体   繁体   中英

2goarray works in cmd but not powershell

I am trying to use 2goarray to write a.ico file to a go file so that I can use it in systray .

My problem is that this works in cmd :

TYPE icon.ico | 2goarray Data icon > icon.go

But running the equivalent command in powershell does not:

Get-Content .\icon.ico | 2goarray Data icon | Out-File -FilePath .\icon.go -Encoding UTF8

When I say it doesn't work, I don't mean an error occurs, I mean that the array produced by 2goarray is not correct, it contains data that systray doesn't recognize as an icon.

For reference, here is the working icon.go, here is the broken/corrupted one produced by powershell, and here is the icon I am using.

I suspect it has something to do with the way that powershell passes things as objects, but I'm not sure?

Your challenge is to pipe binary data in PowerShell, which is not that straight forward. I tested your example with this command and I get the "working" icon.go:

Start-Process 2goarray -ArgumentList "Data icon" -RedirectStandardInput .\icon.ico -RedirectStandardOutput .\icon.go

But this solution seems to be quite slow compared to cmd. From PowerShell you can also always call cmd if you want to, which works surprisingly faster for your example:

Start-Process cmd -ArgumentList "/c TYPE icon.ico | 2goarray Data icon > icon.go"

Often, it is a bad design to call cmd from PowerShell, because PowerShell can nearly do everything that cmd can do, and often more, but for your example, this seems to be the better solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM