Hi, I have a console application that modifies MP3's. Currently I'm writing the modified MP3 to a file using a filestream.
Some users have requested to be able to pipe the MP3 directly to their mediaplayer, like this:
I know this requires me to write to StdOut (Console.OpenStandardOutput). My problem is that when I write to StdOut and the user doesn't pipe the output to their mediaplayer, the MP3 binary data is shown in the console window, the computer starts beeping and the console window can't be closed anymore, forcing the user to reboot.
How can I detect if the user is piping the data to their mediaplayer, so I know if I need to write to StdOut or not? Do I need to check the commandline arguments or is there an other way to do this? I'm not sure how to handle this properly.
Some users have requested to be able to pipe the MP3 directly to their mediaplayer, like this:
Code:
application.exe -a 512 -b 44100 | "C:\mediaplayer.exe"
How can I detect if the user is piping the data to their mediaplayer, so I know if I need to write to StdOut or not? Do I need to check the commandline arguments or is there an other way to do this? I'm not sure how to handle this properly.
vb.net Code:
Using outStream As New FileStream(filename, FileMode.Create, FileAccess.ReadWrite) Dim buffer(8191) As Byte Dim byteCount As Integer = inStream.Read(buffer, 0, buffer.Length) Do Until byteCount = 0 outStream.Write(buffer, 0, byteCount) byteCount = inStream.Read(buffer, 0, buffer.Length) Loop End Using Using outStream As Stream = Console.OpenStandardOutput() Dim buffer(8191) As Byte Dim byteCount As Integer = inStream.Read(buffer, 0, buffer.Length) Do Until byteCount = 0 outStream.Write(buffer, 0, byteCount) byteCount = inStream.Read(buffer, 0, buffer.Length) Loop End Using