-6

In the program i need to have a way of reading a command line thats given to the program with the running of the program. so for example:

"flying-postman.exe mail.txt boeing-spec.txt 23:00 –o itinerary.txt"

so this line should firstly run the program(which is flying-postman.exe) and then it also needs to feed those 4 following variables to the program.

So i know that ReadLine() exists, but it wont be helpful in the case because i need it to take those variables at the same time the program is called not after the program is called. i.e i dont want it to run the program then wait for the user to enter in the values.

  • Is this a GUI application, or a Console one? Also see: [`Environment.CommandLine`](https://learn.microsoft.com/en-us/dotnet/api/system.environment.commandline?view=netframework-4.8) – Ron Beyer May 21 '19 at 14:21
  • Hi. I understand there might be a language barrier here but you could you clarify one thing for me. Are you asking how to get the parameters given to *your* program? Or are you asking how to pass parameters to a program you want to start from your program? Or are you asking how to read the output from this program you want to start? Right now it's not very clear. For instance, is "flying-postman.exe" your program or one you want to start? – Lasse V. Karlsen May 21 '19 at 14:23
  • 1
    If you want to get the parameters passed to your program, the answer that snuck in before the question was closed is what you want, or you may want to use `Environment.GetCommandLineArgs()`. – Lasse V. Karlsen May 21 '19 at 14:25
  • 1
    If you want to start a different program and pass parameters to that, you should look at `Process.Start`. – Lasse V. Karlsen May 21 '19 at 14:25

1 Answers1

0

The entry point to a console app is main, which takes an array of strings, something like

class Program
{
    static void Main(string[] args)
    {
    }
}

If you call your program with some arguments, the first will be the exe name, and the rest your strings.

doctorlove
  • 18,872
  • 2
  • 46
  • 62