Re: Command-Line Arguments
From: Ralph (nt_consulting32_at_hotmail.com)
Date: 02/24/04
- Next message: Dib: "SQL"
- Previous message: Rick Rothstein: "Re: How to change drive serial no"
- In reply to: John: "Command-Line Arguments"
- Next in thread: Rick Rothstein: "Re: Command-Line Arguments"
- Reply: Rick Rothstein: "Re: Command-Line Arguments"
- Reply: Tony Proctor: "Re: Command-Line Arguments"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 24 Feb 2004 11:44:08 -0600
"John" <anonymous@discussions.microsoft.com> wrote in message
news:BAC6D939-812C-489E-B487-CCC29CE4ED18@microsoft.com...
> I use a very simple method of parsing the command-line to get the
arguments, which are currently assumed to be space delimited. However, I
need to make a change to one of my utilities to accept a fully qualified
filename, including the path. This requirements means that I can no longer
use space delimited arguments because paths and filenames can have spaces.
>
> What is the best method of passing arguments when spaces are integral to
one or more of the arguments (i.e., filenames, paths, etc.)?
>
> Thanks,
> John
John,
You will save yourself (and your clients) some time and trouble if you adopt
from the beginning a "schema" or standard convention for handling command
line arguments.
There are 3 basic forms:
1) A traditional 'C' form where you have the executable and each of the
arguments.
example: 'exe file1 file2 ...'
With this form "spaces" were considered 'native' delimiters and
anything with
spaces had to be quoted.
2) The Dos/VMS form where you can present Options with values.
Options are delimited with a '/' and the value assigned with a
'='
Single options are supported without the '=' sign.
"exe /USER=value /NAME="Conan the barbarian" /I"
Strings were handled in two ways - force using quotes or
capturing everything until you came to the next flag '/'.
(In this schema a '-' was often used to negate a particular
option.)
3) The UNIX or AT&T getopts form with options and values.
Options are delimited with the '-' flag
and if any values they are assigned directly behind the key.
Options could be combined as in "-arw -d"
Only single characters were supported as options
colons were then used to indicate string values.
Example: 'exe -U23 -N:Conan the barbarian -i
IHMO It is important to accept one of these scheme and stick to it.
You should also always provide a "/?" option which when given will output a
Help string. You can easily use this as the correct response for any
parameters errors.
Also there is nothing wrong with requiring your user to use quotes to
correctly enter whole values with spaces.
HTH
-ralph
- Next message: Dib: "SQL"
- Previous message: Rick Rothstein: "Re: How to change drive serial no"
- In reply to: John: "Command-Line Arguments"
- Next in thread: Rick Rothstein: "Re: Command-Line Arguments"
- Reply: Rick Rothstein: "Re: Command-Line Arguments"
- Reply: Tony Proctor: "Re: Command-Line Arguments"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|