Binary pipe into to two programs

I have a video stream over a udp connection that I'm transferring using ncat. I'm piping this into mplayer to play it. I'm doing this just on the normal command line. Everything works fine.The command I'm running is:

ncat -l -p 5000 --udp | mplayer -vo direct3d -cache 1028 -

What I want to do is change the pipe to send it to mplayer AND to another ncat process that fowards it to another computer. My research led me first to a Windows implementation of tee, but that doesn't work because it tee's to a file and to the next command in the pipe instead of to two commands.

So then I was reading about using PowerShell and I think that's the only way to do it without having to write code. I'm a proficient programmer so I can write a program to do this if needed, but I was hoping I could just write a script and make this happen. However, I'm not getting very far...

My first attempt was modeled after this example I found here:

PS > "123" | % { 
    $_.Replace( "1", "a"), 
    $_.Replace( "2", "b" ) 
}

Seems to work for this simple example, but it's not working for what I want to do. Seems this is processing an item at a time, but I have a continuous stream.

I tried to replicate my existing ncat to mplayer example and couldn't even get that to work. For whatever reason, I don't get any output to the console from mplayer and the mplayer video window never starts. I'm not really sure why though.

Another issue that I came across was that PowerShell doesn't seem to pipe bytes as straight bytes. That confused me a bit because it seems restrictive, but I guess most people use PowerShell for text processing so it kind of makes sense. This led me to find a Get-ProcessOutputAsBinary command here that I tried to make work. I was able to finally get some mplayer output to the console, however it only happened after I killed the ncat process. Here's what I tried:

.\Get-ProcessOutputAsBinary.ps1 "ncat.exe" "-l -p 5000 --udp" | mplayer -vo direct3d -cache 1028 -
Maybe it's because I'm a programmer and don't write scripts very often, but this seems overly complicated. I guess I can think of a ton of reasons you'd want to pipe output (binary or otherwise) to two (or more) other commands and I don't understand why it's so difficult. I'm also not understand why I can't even replicate what I can do on a standard windows command line. Am I just missing something?

February 22nd, 2015 10:25pm

There is no TEE in Windows.  This is also not a scripting question but a question about how to use a specific utility.
Free Windows Admin Tool Kit Click here and download it now
February 22nd, 2015 11:13pm

I know there's no "official" tee program, but there are a couple linux ports and they do the same thing. Supposedly in bash you can tee to a program instead of a file, but obviously that doesn't work in Windows.

I guess I don't see why this isn't a scripting question. It really has nothing to do with any of the utilities I mentioned. I'm simply asking how to write a script that can pipe binary output from one utility to two (or more) other utilities that take binary from stdin. Seems like something that is done with a script and would be a scripting question.

February 22nd, 2015 11:27pm

There is not script that can "tee" to programs the way you want.  Perhaps you could write one In C++. Ask in the developers forum but you won't get a solution here.

Free Windows Admin Tool Kit Click here and download it now
February 22nd, 2015 11:32pm

That's what I wanted to know. Thanks.
February 23rd, 2015 12:02am

As for streaming video, I think VLC player might be what you are looking for. You can use it to stream video and it supports console commands. Have a look here:

http://www.videolan.org/doc/streaming-howto/en/

Free Windows Admin Tool Kit Click here and download it now
February 23rd, 2015 1:53am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics