Hacker News new | past | comments | ask | show | jobs | submit login

Agreed that having to drop to .NET is a fail. So usually when trying to learn to do file I/O in a new language you google it. The first few examples I came across were slow and when I looked into it, it was doing as this example did. It's been awhile, but it wasn't obvious how to do it with a stream without resorting to a C# esque version which at that point, you might as well use C#. I'm not sure why there isn't a PS oneliner option like Python's with statement. I really like the idea of PS, but some simple things are more trouble than they're worth.



Well, the most natural way would be to use the pipeline. Instead of writing to the file in the innermost ForEach-Object, just pipe the whole pipeline into Out-File. I'd say it's the most straightforward and natural way, considering that PowerShell is a shell.


> Agreed that having to drop to .NET is a fail.

So many times i run into performance walls with powershell, that calling the .net library directly is basically required.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: