Re: command line arguments best practices
- From: "Ralph" <nt_consulting64@xxxxxxxxx>
- Date: Wed, 17 Aug 2005 15:37:01 -0500
"iceman420205" <iceman420205@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:3522ECAD-A691-479F-A86A-5905C5C3D76F@xxxxxxxxxxxxxxxx
> I have seen a number of posts here and on the net as to how to use
Command$.
> I am familiar with how to create a string, set it equal to Command$, and
then
> parse it or do whatever I want.
>
> However, I am curious as to the best practice in controlling more complex
> parameters.
>
> What is the best delimiter (e.g. slash, hyphen, pipe)?
> For example, MyApp.exe /f /q or MyApp.exe -f -q or MyApp.exe f|q.
>
> What is the best indicator (e.g. single or double letters, numbers)?
> For example, MyApp.exe /fs /q
>
> Should the indicator be followed by another character to help the parsing
> (e.g. colon)?
> For example, MyApp.exe /fs:Hello /q
>
> Should quotation marks be used or discouraged?
> For example, MyApp.exe /hHello or MyApp.exe /h"Hello"
>
> Should spaces be used or discouraged?
> For example, MyApp.exe /a 3456 or MyApp.exe /a3456.
>
> What is the best way to handle paths?
> For example, MyApp.exe /fsc:\temp\blah.txt /q
>
> Once the delimiter is determined, what is the best way to parse Command$?
> Dim sCommand as String
> sCommand = Command$
>
> Load string in an array?
> Dim vCommand As Variant
> vCommand = Split(sCommand, "|")
>
> Replace delimiter with something else?
> sCommand = Replace(sCommand, "/", vbCrLf)
>
> Use Select Case?
>
> Write a separate function?
>
> Make a class?
>
> I prefer to use industry standards and to utilize the experience of the
> best. I apologize if this is too broad and/or lengthy an issue, just a
> personal preference, or not the place to have such a discussion. Thank
you
> for your time and efforts.
>
> iceman420205
>
There are three broad 'standards' for managing and defining protocols for
command line parameters. The different scenarios you have above are pieces
from each.
The first is a simple positional parse using the default delimiter. Then
using whatever rules you want for each parameter for further processing. Ad
hoc, frequently used, and error-prone.
The second is getopts() (published and copyrighted by AT&T since time began.
<g>) which is widely used in Unix and C/C++ runtimes and perhaps comes the
closest to being a 'Standard'.
You can look at the definition and the source at...
http://archive.devx.com/sourcebank/directorybrowse.asp?adType=&dir_id=790&showResType=0&timeSelect=&showFilter=showAll
Its in C but should be easy to puzzle it out for your own application. There
a couple of zillion examples out there.
This standard is characterized by allowing single and multiple character
parameters, is non positional, and provides special characters for string
values (':'), and allows the 'flag' to either be a hyphen or a backslash.
I use a getopts() that I have modified for VB for all my programs that take
complex parameters. If you decided to go that route I can help with some
source.
The other 'standard' is loosely term MSDOS/VMS. It is characterized by a
combination of positional and non-positional parameters, case-insensitive,
and using a separate delimiter for strings (the double quote), and a single
flag (the forward slash).
But you will find that outside of the Unix/C world or special heavy iron
environments - it is pretty much of a free-for-all. <g>
I apologize for not giving an explicit answer for most of your questions as
the answer to all would be something like, "Well, that's ok, but I would do
this..." ie, full of personal opinion (although very sage and valuable
opinions, since they are mine. <g>).
You should pick the style you feel would be less confusing for your users
and adequate for your needs and stick with it. Then go surfing. There are a
couple of zillion pieces of source code out there.
hth
-ralph
.
- Follow-Ups:
- Re: command line arguments best practices
- From: Tony Proctor
- Re: command line arguments best practices
- From: iceman420205
- Re: command line arguments best practices
- References:
- command line arguments best practices
- From: iceman420205
- command line arguments best practices
- Prev by Date: FAXCOMEXLib question
- Next by Date: Re: Array: subscript out of range
- Previous by thread: Re: command line arguments best practices
- Next by thread: Re: command line arguments best practices
- Index(es):
Relevant Pages
|