Passing Parameters to Console Application

M

Michael Hetrick

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
 
M

Michael Hetrick

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

Jonathan Schafer said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top