-1

I wish to make a command-line file searching program in C#. I want it to have a callable name such as 'search' as well as command-line arguments such as 'search name'. How might one implement this in C#? I figure I will have to create a new command line command, but I don't know how parameters might be passed to C# methods.

EpicNicks
  • 21
  • 1
  • 7
  • 1
    There are several good nuget packages out there for parsing command line arguments. Regardless, you need to be more specific about the issue you are encountering. – BradleyDotNET Jan 16 '19 at 20:26
  • I thought I was pretty specific. Callable name, passable commands. – EpicNicks Jan 16 '19 at 20:30
  • Or, as an off-the-wall alternative, you could create one (or a set of) PowerShell _Cmdlets_ in a "module". Powershell handles aliases, command completion, intelligent "pipelining", etc. much better than cmd.exe. – Flydog57 Jan 16 '19 at 20:48
  • A sample usage? Sample code? "How to use command line arguments to do an unspecified thing" is fairly broad. Apparently you were just looking for the `args` array, I assumed you had at least gotten that far. – BradleyDotNET Jan 16 '19 at 21:46
  • That wasn't all. I mentioned how one would make a cmd/PowerShell command to execute with those arguments. As crazy as it might sound, they never really taught me the full meaning of public static void Main(String[] args), and the internet doesn't directly either. – EpicNicks Jan 17 '19 at 03:02

2 Answers2

0

Parameters passed from consoles can be accessed if the Main method has parameter string[] args. Alternatively, this can be accessed using the method System.Environment.GetCommandLineArgs(). Unlike C/C++, this does not include the name of the program.

Here is a question on adding aliases: Aliases in Windows command prompt This would enable you to type 'search' instead of search.exe.

Gnbrkm41
  • 238
  • 3
  • 9
0

For debugging you can set command line arguments in the project properties.

enter image description here

Then simply access the arg parameter in the main event (for a console app).

enter image description here

Neil B
  • 2,096
  • 1
  • 12
  • 23