Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.IO;
- // usage: multicat.exe - logfile1.log logfile2.log
- // '-' means STDOUT
- class Program
- {
- public static void Main(string[] args)
- {
- try
- {
- foreach(var path in args)
- {
- if (path == "-")
- writers[path] = Console.Out;
- else
- writers[path] = new StreamWriter(path);
- }
- string input;
- while ((input = Console.ReadLine()) != null)
- {
- foreach (var writer in writers.Values)
- {
- writer.WriteLine(input);
- }
- }
- }
- finally
- {
- foreach (var kvp in writers)
- {
- if (kvp.Key != "-")
- kvp.Value.Dispose();
- }
- }
- }
- static readonly IDictionary<string, TextWriter> writers = new SortedDictionary<string, TextWriter>();
- }
Advertisement
Add Comment
Please, Sign In to add comment