Page 1 of 1

Help redirecting files as input/output in C#

Posted: Sun Feb 09, 2014 7:28 pm
by Jackolantern
Alright I am trying to use C# for a school lab. It is either that or use Java like everyone else or learn Ada :|

But we have to get all input from a text file and output to another text file. In Java, this is as simple as having 2 text files and entering

Code: Select all

C:\>java program < input.txt > output.txt
and then all input comes from the input text file and all output goes to the output text file.

Looking up the same thing in C#, I can't seem to find how to do this in a simple way. All the .NET options are all giving options using the processes, 40+ lines of code, dozens of objects, and some even using TPL. Just writing the code to expect keyboard input and then piping the file name or trying the Java way doesn't work. Is there a simple way to do this?

EDIT: Oh, and this is just a simple console application with POCOs ("Plain Ol' CLR Objects").

Re: Help redirecting files as input/output in C#

Posted: Mon Feb 10, 2014 7:26 am
by a_bertrand
If your soft is a command line tool you can do exactly the same in C#.

Re: Help redirecting files as input/output in C#

Posted: Mon Feb 10, 2014 12:53 pm
by Jackolantern
Hmm...I must have had some kind of coding error, as it is working fine now. Thanks! :)

Re: Help redirecting files as input/output in C#

Posted: Mon Feb 10, 2014 3:38 pm
by Jackolantern
Ohhh, that crap I was talking about finding before, with 40 lines of code, the process object, etc., was for taking in file data for compilation. That would be quite rare someone would need that, but for some reason it was all I was finding online.

And the reason it didn't work the first time I tried that sent me looking online was just due to a type-mismatch that gave an odd error message :|