Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27418

Console write to StdOut

$
0
0
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:

Code:

application.exe -a 512 -b 44100 | "C:\mediaplayer.exe"
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.

vb.net Code:
  1. Using outStream As New FileStream(filename, FileMode.Create, FileAccess.ReadWrite)
  2.     Dim buffer(8191) As Byte
  3.     Dim byteCount As Integer = inStream.Read(buffer, 0, buffer.Length)
  4.     Do Until byteCount = 0
  5.         outStream.Write(buffer, 0, byteCount)
  6.         byteCount = inStream.Read(buffer, 0, buffer.Length)
  7.     Loop
  8. End Using
  9.  
  10. Using outStream As Stream = Console.OpenStandardOutput()
  11.     Dim buffer(8191) As Byte
  12.     Dim byteCount As Integer = inStream.Read(buffer, 0, buffer.Length)
  13.     Do Until byteCount = 0
  14.         outStream.Write(buffer, 0, byteCount)
  15.         byteCount = inStream.Read(buffer, 0, buffer.Length)
  16.     Loop
  17. End Using

Viewing all articles
Browse latest Browse all 27418

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>