1

I'm looking for a way to read bytes from stdin and pass them to stdout. I've found this question which talks about how to read from stdin using text encoding. I want read and write using raw or binary encoding.

Getting stdin into the Powershell stream

The question says it is non-trival to deal with decoding and encoding. If it helps this is the way I am doing this in VBScript:

Do While Not WScript.StdIn.AtEndOfStream
    WScript.StdOut.Write(WScript.StdIn.Read(1024))
Loop

This following does not work because the encoding is wrong. I'm using redirection just for illustrative purposes. I need to be able to read from stdin.

powershell -NoProfile -Command "$Input" <file1.exe >file2.exe
Community
  • 1
  • 1
  • Please take a step back and describe the actual problem you're trying to solve instead of what you perceive as the solution. What do you "need to be able to read from stdin"? From where? What doesn't work as expected when you use `$input`? Why do you need PowerShell to emulate a pipe in the first place? – Ansgar Wiechers Jan 07 '17 at 12:17
  • I want to copy a binary file from Linux to Windows. I am using a winrs type client to connect and execute a remote command on the Windows system. My Linux pipeline is "cat binary-file | winrs-client-program remote-host "cscript //nologo copy.vbs >binary-file". This requires having the VBScript file already on the remote system. I'd rather do this with one power shell command line using the -command option. I need $Input to do raw or binary encoding. – user7385667 Jan 07 '17 at 19:47
  • `smbclient -U user%pass //host/share --directory some/path "put 'your.file'"`? – Ansgar Wiechers Jan 07 '17 at 20:29
  • I can not use smbclient and the destination is not shared. I need to use the winrs client. How can I perform the equivalent of that VBScript using powershell with raw or byte encoding. – user7385667 Jan 07 '17 at 21:05
  • `powershell -NoProfile -Command $i = [Console]::OpenStandardInput(); $o = [Console]::OpenStandardOutput(); $i.CopyTo($o); $i.Close(); $o.Close()` – user4003407 Jan 08 '17 at 04:50

0 Answers0