By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,336 Members | 1,293 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,336 IT Pros & Developers. It's quick & easy.

Passing Parameters to Console Application

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

consoleapp.exe /o \\fileshare\origindirectory /d
\\fileshare\destinationdirectory

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

Michael Hetrick
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Thanks - it was the part about the args[] in Main!

"Jonathan Schafer" <jschafer@*NOSPAM*brierley.a.b.c.com> wrote in message
news:43********************************@4ax.com...
On Tue, 15 Jul 2003 20:59:43 -0400, "Michael Hetrick"
<m1******@gc.com> wrote:
How would I pass parameters to a console application? I would like to do
something like this:

consoleapp.exe /o \\fileshare\origindirectory /d
\\fileshare\destinationdirectory

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

Michael Hetrick


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\origindirectory,
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

Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.