我如何读取一个c#控制台应用程序的整个命令行,因为它是被输入的?(复制)

时间:2023-01-23 20:44:35

This question already has an answer here:

这个问题已经有了答案:

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.

我正在编写一个小型的REPL控制台应用程序,我读取一个命令,将它拆分,然后使用一个piss-poor switch语句来决定调用哪个方法(而不是使用策略模式)。然后,我将每个命令放入历史记录中,以便进行审计。

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?

是否可以以某种方式获得整个命令行?

2 个解决方案

#1


7  

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

您可以获得最初通过传递给程序的整个命令行

Environment.CommandLine

Environment.CommandLine

#2


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()

#1


7  

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

您可以获得最初通过传递给程序的整个命令行

Environment.CommandLine

Environment.CommandLine

#2


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()