0

I'm creating a small commandline tool for a customer and trying to verify its output. The output is been written to the commandline itself. Since its rather a huge file that's been used as an input file and thus a huge out to write to the commandline, I wanted the output to redirect to a file. Usually I use use commandline arguments like so to redirect the output to a file:

a.exe ./input.txt > ./ouput.txt

However, in my program, I try to verify the input:

static void Main(string[] args)
{
    if (args.Length != 1)
        throw new ArgumentException();
    ...

And args now is:

args[0] = ./input.txt
args[1] = >
args[2] = ./ouput.txt

Honestly I personally still expect only one argument, since the file is been created and thus the shell does understand what I mean. So... what am I doing wrong? Should I use args or something else? Thank you in advance!

van Nijnatten
  • 404
  • 5
  • 15
  • Guess you're gonna have to change your verification code. – Sam Axe Nov 07 '13 at 11:08
  • Try to add parenthesis, like this: (a.exe ./input.txt) > ./ouput.txt – Alexandre Nov 07 '13 at 11:15
  • For me, it works as expected. May you also try `a.exe ./input.txt>./ouput.txt` (without spaces)? – Alex Filipovici Nov 07 '13 at 11:18
  • `args.Length` should be 1 as you expect. How are you invoking your tool? Are you typing the commandline in a shell? – Reda Nov 07 '13 at 11:27
  • Dan-o: I thought about using external libraries instead (http://stackoverflow.com/questions/491595/best-way-to-parse-command-line-arguments-in-c) but for such a simple thing I just did not want to bother. It also would not make anything more simple in my case. Alexandre: Can't do that in VS2012, can I? AlexFilipovici: That would have worked if I did not use any quotes around my file names ;-) Thanks anyways! – van Nijnatten Nov 07 '13 at 11:38
  • @user2266486 I'm debugging in VS2012 – van Nijnatten Nov 07 '13 at 11:41

1 Answers1

0

Are you passing the arguments through Visual Studio? It will only work if you untick Enable the Visual Studio hosting process.

enter image description here

Image and explanation from here.

Community
  • 1
  • 1
Ilian
  • 5,113
  • 1
  • 32
  • 41