Passing Parameters to Console Application

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Hetrick

    #1

    Passing Parameters to Console Application

    How would I pass parameters to a console application? I would like to do
    something like this:

    consoleapp.exe /o \\fileshare\ori gindirectory /d
    \\fileshare\des tinationdirecto ry

    I'm not sure how to start the console app to read from the command line.
    Any assistance would be appreciated!

    Michael Hetrick


  • Michael Hetrick

    #2
    Re: Passing Parameters to Console Application

    Thanks - it was the part about the args[] in Main!

    "Jonathan Schafer" <jschafer@*NOSP AM*brierley.a.b .c.com> wrote in message
    news:43a9hvgn3f lv0a1g8t2nbqkjj 0k2ut2v67@4ax.c om...[color=blue]
    > On Tue, 15 Jul 2003 20:59:43 -0400, "Michael Hetrick"
    > <m1hetric@gc.co m> wrote:
    >[color=green]
    > >How would I pass parameters to a console application? I would like to do
    > >something like this:
    > >
    > >consoleapp.e xe /o \\fileshare\ori gindirectory /d
    > >\\fileshare\de stinationdirect ory
    > >
    > >I'm not sure how to start the console app to read from the command line.
    > >Any assistance would be appreciated!
    > >
    > >Michael Hetrick
    > >[/color]
    >
    > I'm a little unsure what you are asking...
    >
    > If you are asking how to start a console program from another .NET
    > program (with or without parameters), use the Process class. You can
    > set up the name of the exe to run, parameters, etc.
    >
    > If you are wondering how to handle parameters passed to a .NET console
    > program, they are already parsed for you via the args[] in the main
    > function. Each parameter is in the array and I believe the arguments
    > are split on white space. So, given your above command line, args[0]
    > would contain /o, args[1] would contain \\fileshare\ori gindirectory,
    > etc.
    >
    > There may be an issue however, if your directory path contains one or
    > more spaces in it. Then it may split that argument into separate
    > arguments where the spaces exist and you'd have to piece it back
    > together.
    >
    > If neither of these answers your question, then either someone who
    > understood your question better will answer or you can post a more
    > specific question.
    >
    > Jonathan Schafer[/color]


    Comment

    Working...