Console Mode argument access

V

VC#user

Hi All,

I am relatively new to c#. I am trying to use a code that works fine in the UI mode in console mode.

The application takes a list of files (input in xml) and generates xml files (output) compatible to another tool.

the UI works fine. But I am trying to modify the existing source code to accept arguments while invoking the exe in command line. But in the formmain.cs i have a function that generates the required xml with the following inputs.


public bool bGenerateXml ()
{
bool b_status = false;
{
if (m_bGui)
{
m_ModuleNames = m_SettingsForm.InputFiles;
m_OutputFileName = m_SettingsForm.OutputFilePath;

}

But I am trying to set the m_ModuleNames & m_OutputFileName by taking the input filename and output filename as argument (from program.cs) file but I am facing problems in setting these variables. either related to protection or the type conversion etc.
can someone help on how I can set these variables from program.cs and being able to use the console application.

thanks a lot.
 
A

Anders Eriksson

But I am trying to set the m_ModuleNames & m_OutputFileName by taking the input filename and output filename as argument (from program.cs) file but I am facing problems in setting these variables. either related to protection or the type conversion etc.
can someone help on how I can set these variables from program.cs and being able to use the console application.

in program.cs you have
class Program
{
static void Main(string[] args)
{
}
}


All arguments you give on the command line will end up in the args array
e.g.
myprogram.exe inputfile outputfile

in main() you get
m_ModuleNames = args[0]; // will set m_ModuleNames to inputfile
m_OutputFileName = args[1]; // will set m_OutputFileName to outputfile


Just realized that you want to enter a number of input files...
Then you I would recommend that you use one of the already made command
line argument parsers

http://goo.gl/Xymruw


// Anders
 
A

Arne Vajhøj

But I am trying to set the m_ModuleNames & m_OutputFileName by taking
the input filename and output filename as argument (from program.cs)
file but I am facing problems in setting these variables. either
related to protection or the type conversion etc.
can someone help on how I can set these variables from program.cs and
being able to use the console application.

in program.cs you have
class Program
{
static void Main(string[] args)
{
}
}


All arguments you give on the command line will end up in the args array
e.g.
myprogram.exe inputfile outputfile
Yes.

in main() you get
m_ModuleNames = args[0]; // will set m_ModuleNames to inputfile
m_OutputFileName = args[1]; // will set m_OutputFileName to outputfile

Yes, but.

With a typical naming convention m_ prefix would indicate non-static
fields.

:)

Arne
 
R

rbowman

Anders said:
in main() you get
m_ModuleNames = args[0]; // will set m_ModuleNames to inputfile
m_OutputFileName = args[1]; // will set m_OutputFileName to outputfile

It would also be good to check args.Length to be sure the user entered 2
parameters and have some sort of plan if they failed to do so.
 

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