I need to pipe some data to a program\'s stdin.
Would this work for you?
$fileName = "C:\test.txt"
$data = [IO.File]::ReadAllText($fileName)
$prefix = ([BitConverter]::GetBytes($data.Length) | foreach-object {
"\x{0:X2}" -f $_
}) -join ""
"{0}{1}" -f $prefix,$data
You can replace "\x{0:X2}" -f $_
with $_ -as [Char]
if you want $prefix
to contain the raw data representations of the bytes.