473,395 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

command line interface programming question

djc
I'm new to this and was wondering what the options are for interpreting the
command line using a CLI program. Specifically methods for interpreting the
parameters passed to the program on the command line.

I noticed that visual studio adds the following for you when creating a new
CLI program:

void main(string[] args)
{
}

so obviously there is an array of strings to use.

1) is this the standard method or are there other options? (i know thats
probably a dumb question)
2) is the args array populated by each parameter passed to the program using
a 'space' as the delimiter?
3) any recomendations for a beginner on ways to parse a command line? for
example, here are some typical structures:
command.exe param1 param2 -easy enough, simple usage of the args array
command.exe -h param1 -z param2 -using switches with a parameter for the
specific switch.
command.exe /h param1 /z param2
command.exe /h:param1 /z:param2

how to implement these different structures? I think I prefer the second way
I listed but would also want it to be flexible enough so that the order of
the switches did not matter.

I think I'm posting too early here and I don't seem to be asking any good
specific questions. Any recomendations or links to where I could find
specific information on implementing these things would be appreciated.

thanks.
Mar 16 '06 #1
8 1828
Hello djc,

d> I'm new to this and was wondering what the options are for
d> interpreting the command line using a CLI program. Specifically
d> methods for interpreting the parameters passed to the program on the
d> command line.
d> I noticed that visual studio adds the following for you when creating
d> a new CLI program:
d>
d> void main(string[] args)
d> {
d> }
d> so obviously there is an array of strings to use.

d> 1) is this the standard method or are there other options? (i know
d> thats
d> probably a dumb question)

Yep, it is. but u may even don't specify string[] args

d> 2) is the args array populated by each parameter passed to the
d> program using a 'space' as the delimiter?

yes

d> 3) any recomendations for a beginner on ways to parse a command line?
d> for
d> example, here are some typical structures:
d> command.exe param1 param2 -easy enough, simple usage of the args
d> array
d> command.exe -h param1 -z param2 -using switches with a parameter
d> for the
d> specific switch.
d> command.exe /h param1 /z param2
d> command.exe /h:param1 /z:param2

You need not parse it, because all your parameters are already parsed, and
located in args array.
To get access to them use args[<number>]

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Mar 16 '06 #2
Hi,
here is a sample code which will answer most of your questions. for the
alst questrion, i generaly prefere /h:param1 /p:param2 because it gives some
meaning to the params. I recomend to add a help param like /? or -h
namespace CommandLine

{

class Program

{

static void Main(string[] args)

{

foreach (string s in args)

{

Console.WriteLine(s);

}

}

}

}

thnak you.

now for your question

"djc" <no***@nowhere.com> wrote in message
news:Oa**************@TK2MSFTNGP14.phx.gbl...
I'm new to this and was wondering what the options are for interpreting
the
command line using a CLI program. Specifically methods for interpreting
the
parameters passed to the program on the command line.

I noticed that visual studio adds the following for you when creating a
new
CLI program:

void main(string[] args)
{
}

so obviously there is an array of strings to use.

1) is this the standard method or are there other options? (i know thats
probably a dumb question)
2) is the args array populated by each parameter passed to the program
using
a 'space' as the delimiter?
3) any recomendations for a beginner on ways to parse a command line? for
example, here are some typical structures:
command.exe param1 param2 -easy enough, simple usage of the args array
command.exe -h param1 -z param2 -using switches with a parameter for
the
specific switch.
command.exe /h param1 /z param2
command.exe /h:param1 /z:param2

how to implement these different structures? I think I prefer the second
way
I listed but would also want it to be flexible enough so that the order of
the switches did not matter.

I think I'm posting too early here and I don't seem to be asking any good
specific questions. Any recomendations or links to where I could find
specific information on implementing these things would be appreciated.

thanks.

Mar 16 '06 #3
djc
Thanks for the input. I appreciate it.

"Michael Nemtsev" <ne*****@msn.com> wrote in message
news:9c**************************@msnews.microsoft .com...
Hello djc,

d> I'm new to this and was wondering what the options are for
d> interpreting the command line using a CLI program. Specifically
d> methods for interpreting the parameters passed to the program on the
d> command line.
d> I noticed that visual studio adds the following for you when creating
d> a new CLI program:
d>
d> void main(string[] args)
d> {
d> }
d> so obviously there is an array of strings to use.
d> 1) is this the standard method or are there other options? (i know
d> thats
d> probably a dumb question)

Yep, it is. but u may even don't specify string[] args

d> 2) is the args array populated by each parameter passed to the
d> program using a 'space' as the delimiter?

yes

d> 3) any recomendations for a beginner on ways to parse a command line?
d> for
d> example, here are some typical structures:
d> command.exe param1 param2 -easy enough, simple usage of the args
d> array
d> command.exe -h param1 -z param2 -using switches with a parameter
d> for the
d> specific switch.
d> command.exe /h param1 /z param2
d> command.exe /h:param1 /z:param2

You need not parse it, because all your parameters are already parsed, and
located in args array.
To get access to them use args[<number>]

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do

not cease to be insipid." (c) Friedrich Nietzsche

Mar 16 '06 #4
djc
Thanks for the input. I appreciate it.

"Mohammad Shalabi" <ms******@microsoft.com> wrote in message
news:eI****************@TK2MSFTNGP11.phx.gbl...
Hi,
here is a sample code which will answer most of your questions. for the
alst questrion, i generaly prefere /h:param1 /p:param2 because it gives some meaning to the params. I recomend to add a help param like /? or -h
namespace CommandLine

{

class Program

{

static void Main(string[] args)

{

foreach (string s in args)

{

Console.WriteLine(s);

}

}

}

}

thnak you.

now for your question

"djc" <no***@nowhere.com> wrote in message
news:Oa**************@TK2MSFTNGP14.phx.gbl...
I'm new to this and was wondering what the options are for interpreting
the
command line using a CLI program. Specifically methods for interpreting
the
parameters passed to the program on the command line.

I noticed that visual studio adds the following for you when creating a
new
CLI program:

void main(string[] args)
{
}

so obviously there is an array of strings to use.

1) is this the standard method or are there other options? (i know thats
probably a dumb question)
2) is the args array populated by each parameter passed to the program
using
a 'space' as the delimiter?
3) any recomendations for a beginner on ways to parse a command line? for example, here are some typical structures:
command.exe param1 param2 -easy enough, simple usage of the args array command.exe -h param1 -z param2 -using switches with a parameter for
the
specific switch.
command.exe /h param1 /z param2
command.exe /h:param1 /z:param2

how to implement these different structures? I think I prefer the second
way
I listed but would also want it to be flexible enough so that the order of the switches did not matter.

I think I'm posting too early here and I don't seem to be asking any good specific questions. Any recomendations or links to where I could find
specific information on implementing these things would be appreciated.

thanks.


Mar 16 '06 #5
On Thu, 16 Mar 2006 15:50:11 -0500, "djc" <no***@nowhere.com> wrote:
Thanks for the input. I appreciate it.

"Michael Nemtsev" <ne*****@msn.com> wrote in message
news:9c**************************@msnews.microsof t.com...
Hello djc,

d> I'm new to this and was wondering what the options are for
d> interpreting the command line using a CLI program. Specifically
d> methods for interpreting the parameters passed to the program on the
d> command line.
d> I noticed that visual studio adds the following for you when creating
d> a new CLI program:
d>
d> void main(string[] args)
d> {
d> }
d> so obviously there is an array of strings to use.
>

d> 1) is this the standard method or are there other options? (i know
d> thats
d> probably a dumb question)

Yep, it is. but u may even don't specify string[] args

d> 2) is the args array populated by each parameter passed to the
d> program using a 'space' as the delimiter?

yes

d> 3) any recomendations for a beginner on ways to parse a command line?
d> for
d> example, here are some typical structures:
d> command.exe param1 param2 -easy enough, simple usage of the args
d> array
d> command.exe -h param1 -z param2 -using switches with a parameter
d> for the
d> specific switch.
d> command.exe /h param1 /z param2
d> command.exe /h:param1 /z:param2

You need not parse it, because all your parameters are already parsed, and
located in args array.
To get access to them use args[<number>]

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do

not
cease to be insipid." (c) Friedrich Nietzsche

By the way, you can also make the Main method return an integer (or I guess
anything else). I always change the code generated by the IDE to read:

static int Main(string[] args)
{
}

That helps loads when running a console app from the scheduler and you need to
have a return value.

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
Mar 17 '06 #6
Here is a MSH "style" parser I did a while back. Define your expected args
via attributes in a class and it parses your command line (ints, string,
arrays, etc). Your arg class is populated with the results or throws your
user defined error message for the type in error. Also has pretty help that
is generated from your arg types.
http://channel9.msdn.com/ShowPost.aspx?PostID=54420

--
William Stacey [MVP]

"djc" <no***@nowhere.com> wrote in message
news:Oa**************@TK2MSFTNGP14.phx.gbl...
| I'm new to this and was wondering what the options are for interpreting
the
| command line using a CLI program. Specifically methods for interpreting
the
| parameters passed to the program on the command line.
|
| I noticed that visual studio adds the following for you when creating a
new
| CLI program:
|
| void main(string[] args)
| {
| }
|
| so obviously there is an array of strings to use.
|
| 1) is this the standard method or are there other options? (i know thats
| probably a dumb question)
| 2) is the args array populated by each parameter passed to the program
using
| a 'space' as the delimiter?
| 3) any recomendations for a beginner on ways to parse a command line? for
| example, here are some typical structures:
| command.exe param1 param2 -easy enough, simple usage of the args array
| command.exe -h param1 -z param2 -using switches with a parameter for
the
| specific switch.
| command.exe /h param1 /z param2
| command.exe /h:param1 /z:param2
|
| how to implement these different structures? I think I prefer the second
way
| I listed but would also want it to be flexible enough so that the order of
| the switches did not matter.
|
| I think I'm posting too early here and I don't seem to be asking any good
| specific questions. Any recomendations or links to where I could find
| specific information on implementing these things would be appreciated.
|
| thanks.
|
|
Mar 17 '06 #7
Otis Mukinfus <ph***@emailaddress.com> wrote:

<snip>
By the way, you can also make the Main method return an integer (or I guess
anything else). I always change the code generated by the IDE to read:


No, you can't change it to return anything else (and still be an entry
point). Basically, the four valid Main method entry point signatures
are:

static void Main(string[] args)
static void Main()
static int Main(string[] args)
static int Main()

It's in section 10.1 (of the ECMA spec for C# 1.1).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 17 '06 #8
djc
I'll check it out. Thanks.

"William Stacey [MVP]" <wi************@gmail.com> wrote in message
news:uo**************@TK2MSFTNGP09.phx.gbl...
Here is a MSH "style" parser I did a while back. Define your expected args via attributes in a class and it parses your command line (ints, string,
arrays, etc). Your arg class is populated with the results or throws your
user defined error message for the type in error. Also has pretty help that is generated from your arg types.
http://channel9.msdn.com/ShowPost.aspx?PostID=54420

--
William Stacey [MVP]

"djc" <no***@nowhere.com> wrote in message
news:Oa**************@TK2MSFTNGP14.phx.gbl...
| I'm new to this and was wondering what the options are for interpreting
the
| command line using a CLI program. Specifically methods for interpreting
the
| parameters passed to the program on the command line.
|
| I noticed that visual studio adds the following for you when creating a
new
| CLI program:
|
| void main(string[] args)
| {
| }
|
| so obviously there is an array of strings to use.
|
| 1) is this the standard method or are there other options? (i know thats
| probably a dumb question)
| 2) is the args array populated by each parameter passed to the program
using
| a 'space' as the delimiter?
| 3) any recomendations for a beginner on ways to parse a command line? for | example, here are some typical structures:
| command.exe param1 param2 -easy enough, simple usage of the args array | command.exe -h param1 -z param2 -using switches with a parameter for
the
| specific switch.
| command.exe /h param1 /z param2
| command.exe /h:param1 /z:param2
|
| how to implement these different structures? I think I prefer the second
way
| I listed but would also want it to be flexible enough so that the order of | the switches did not matter.
|
| I think I'm posting too early here and I don't seem to be asking any good | specific questions. Any recomendations or links to where I could find
| specific information on implementing these things would be appreciated.
|
| thanks.
|
|

Mar 20 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jarod | last post by:
Hey I have already written a program that has a user interface, but I would like to add some command line interface too. So if the user run it like: program.exe paramater1 The program do...
2
by: Enrique Bustamante | last post by:
Casting arrays that works on watch and command window but not in code. My application is casting arrays in a way it should work. To test if I was doing something invalid, I wrote a test code that...
14
by: Kevin | last post by:
A couple of easy questions here hopefully. I've been working on two different database projects which make use of multiple forms. 1. Where's the best/recommended placement for command buttons...
34
by: Roman Mashak | last post by:
Hello, All! I'm implementing simple CLI (flat model, no tree-style menu etc.). Command line looks like this: <command> <param1> <param2> ... <paramN> (where N=1..4) And idea is pretty simple: ...
13
by: Pieter Edelman | last post by:
Hi, I'm currently writing a command-line program in Python, which takes commands in the form of: ../myprog.py ARGS So pretty standard stuff. In my case, ARGS is a list of image files. One...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
9
by: bu0461 | last post by:
Hi this is my first post! I'm currently learning C programming language and have just finished structure section. At this point I think I'm able to program some very basic text command line games....
51
by: Ojas | last post by:
Hi!, I just out of curiosity want to know how top detect the client side application under which the script is getting run. I mean to ask the how to know whether the script is running under...
7
by: Jwe | last post by:
Hi, I've written a program which has both a command line interface and Windows form interface, however it isn't quite working correctly. When run from command line with no arguments it should...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.