Search code examples
c#consoleedix12

How to output results to console instead .txt - X12 Parser?


I am testing this EDI standard: X12 Parser (link), now example in link have as result.txt. The code that does this is:

using OopFactory.X12.Parsing;
using OopFactory.X12.Parsing.Model;

namespace MyX12.Edi835Parser
{
    class Program
    {
        static void Main(string[] args)
        {
            Stream transformStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MyX12.Edi835Parser.X12-835-To-CSV.xslt");
            Stream inputStream = new FileStream(args[0], FileMode.Open, FileAccess.Read);
            Stream outputFile = new FileStream(args[1], FileMode.Create, FileAccess.Write);

            X12Parser parser = new X12Parser();
            Interchange interchange = parser.Parse(inputStream);
            string xml = interchange.Serialize();

            var transform = new XslCompiledTransform();
            transform.Load(XmlReader.Create(transformStream));

            transform.Transform(XmlReader.Create(new StringReader(xml)), new XsltArgumentList(), outputFile);
        }
    }
}

As you can see, the code has: Stream outputFile = new FileStream(args1 ... where args1 is in project properties / Debug set as Sample-Output.txt, which is the name of file that would be created.

Now, I want to have the result instead as Sample-Output.txt, in my console, something like this:

Stream outputFile = Console.Write();

Really thanks for help.


Solution

  • Console.OpenStandardOutput() acquires the standard output stream.

    Try replacing

    Stream outputFile = new FileStream(args[1], FileMode.Create, FileAccess.Write);
    

    with

    Stream outputFile = Console.OpenStandardOutput();