8

I am writing a little REPL console app, and I read a command, split it, and use a piss-poor switch statement to decide which method to call (instead of using the Strategy Pattern). I then place each command into a history, for audit.

The command line when starting the app, as typed, is lost as it is already split. I would prefer to have the whole command line and get on with my loop and it's own split routine.

Is it possible to get the whole command line somehow?

ProfK
  • 49,207
  • 121
  • 399
  • 775

2 Answers2

10

You can get the entire command line as originally passed to the program via

Environment.CommandLine

Matthew Watson
  • 104,400
  • 10
  • 158
  • 276
1

First choice is to join it again:

var arg = string.Join(" ", args);

If you want to do this out side main you can ger arguments as:

Environment.GetCommandLineArgs()
Piotr Stapp
  • 19,392
  • 11
  • 68
  • 116
  • 1
    Just a note that using Join won't include quotation marks, backslashes, or any other characters removed by the shell. – Tim Sep 07 '18 at 20:21