Help redirecting files as input/output in C#

For discussions about game development that does not fit in any of the other topics.
Post Reply
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Help redirecting files as input/output in C#

Post 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").
The indelible lord of tl;dr
User avatar
a_bertrand
Posts: 1536
Joined: Mon Feb 25, 2013 1:46 pm

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

Post by a_bertrand »

If your soft is a command line tool you can do exactly the same in C#.
Creator of Dot World Maker
Mad programmer and annoying composer
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

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

Post by Jackolantern »

Hmm...I must have had some kind of coding error, as it is working fine now. Thanks! :)
The indelible lord of tl;dr
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

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

Post 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 :|
The indelible lord of tl;dr
Post Reply

Return to “General Development”