Re: Accessing full command line or parameters WITH QUOTES
- From: "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 27 Nov 2009 19:19:04 -0600
"Bennett" <Bennett@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:0AF8A657-356A-4F70-B779-901DF2B58ECA@xxxxxxxxxxxxxxxx
I'm trying to write a script that manipulates its command line and then
runs
the command line. E.g.:
myscript.vbs "C:\Full Path\Program.exe" /option"Some option" "C:\Some
file"
/etc
which would then execute:
"C:\Full Path\Program.exe" /option"Some other option" "C:\Some other file"
/etc
The problem is that VBScript doesn't allow access to the full command line
like most other languages. Furthermore, the individual parameters get the
quotes stripped, so WScript.Arguments returns:
C:\Full Path\Program.exe
/optionSome other option
C:\Some file
/etc
which is completely assinine because there is no way for me to know how
rebuild the parameters with the quotes inserted properly. What idiot
thought
it would be a good idea to strip all quotes INCLUDING THOSE INSIDE A
PARAMETER??!? Sorry...I'll stop ranting. I'm just flabbergasted that
someone thought it was good idea to manipulate parameters before passing
them
to our scripts.
When I was writing the script on XP, I managed to cheat and grab the
CmdLine
environment variable. However, I need the script to run on Win2008, and
it
doesn't have the CmdLine variable, so I'm out of luck there.
So how do I get around this? How can I either (1) get access to the full
command line similar to the CmdLine environment variable, or (2) get
access
to the full, properly quoted parameters?
I think your script must handle the situations. Any parameter with embedded
spaces must be enclosed in quotes. The script must recognize that any
parameter that might have embedded spaces should always be enclosed in
quotes by the script. In all cases I can think of it will not hurt. In your
example I would say the second parameter is invalid. There should be a space
between /option and "Some other option", so the script can parse it as two
parameters and make sense of it. In other words, there should never be
embedded quotes, only quotes that completely enclose the string.
The only insurmountable problem I've encountered is the inability to include
any quote characters in a parameter. For example I cannot pass the string:
GetObject("LDAP:")
to a script. However, the only time I have had the need to do this is a
script that searches for files that contain specified text strings.
Finally, another solution might be to place the parameters in a text file
and have the VBScript program read the file using the FileSystemObject. No
quotes are stripped off.
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
.
- References:
- Accessing full command line or parameters WITH QUOTES
- From: Bennett
- Accessing full command line or parameters WITH QUOTES
- Prev by Date: Re: Accessing full command line or parameters WITH QUOTES
- Next by Date: Re: Accessing full command line or parameters WITH QUOTES
- Previous by thread: Re: Accessing full command line or parameters WITH QUOTES
- Next by thread: Re: Accessing full command line or parameters WITH QUOTES
- Index(es):
Relevant Pages
|