3

Is it possible to get Powershell to read the stdout of an exe into a byte[] instead of the usual text processed array of lines?

Best I've been able to do is this:

cmd /c foo.exe > foo.tmp
$b = [io.file]::readallbytes('foo.tmp')
del foo.tmp

Yucky, not to mention it is not streamable. Any better way to do this?

1 Answer 1

5

Got some info from the PowerShell team. The short answer is that unfortunately, it is not easy. :-(

The medium length answer is: http://poshcode.org/2175.

The long answer is: Capture and Redirect Binary Process Output

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for following up. I was hoping it wouldn't require the same yucky stuff I had to do in C#, but it's nice to have the code already available on poshcode. Also: you just made Lee Holmes a sale. I'm picking up the 2nd ed of that book. :)
Both of the links in this post are now dead :(
Here's an updated link to the PowerShell Cookbook book - oreilly.com/library/view/powershell-cookbook-4th/9781098101596

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.