Re: Executing a command with options
- From: "McKirahan" <News@xxxxxxxxxxxxx>
- Date: Thu, 3 Jan 2008 09:27:53 -0600
"Warren" <Warren@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:F2F974D8-7635-411D-9FE5-F501EAFA9984@xxxxxxxxxxxxxxxx
I am trying to execute a command with options in a VB Script. I am usingthe
exec method because I want to look at stdout and stderr.
Executing from the command line it looks like this:
d:\HP OpenView\bin\opcragt -status -all
Here is the code I am using:
set shObj = CreateObject("WScript.Shell")
set ragtCmd = shObj.Exec ("d:\HP OpenView\bin\opcragt.cmd")
WScript.Echo ragtCmd.StdErr.ReadAll
WScript.Echo ragtCmd.StdOut.ReadAll
The proir code completes successfully, however when I add options to the
execution such as
set ragtCmd = shObj.Exec ("d:\HP OpenView\bin\opcragt.cmd -status -all")
or
set ragtCmd = shObj.Exec ("d:\HP OpenView\bin\opcragt.cmd /-status /-all")
or
set ragtCmd = shObj.Exec ("d:\HP OpenView\bin\opcragt.cmd /status /all")
stdout reports " 'd:\HP' is not a recognized as an internal or external
command, operable program or batch file."
Any ideas on what is happening and how to correct it?
Will this help? Watch for word-wrap.
Option Explicit
'****
'* 1) Convert longer folder names in "cFOL" to short folder names;
'* 2) append "cCMD";
'* 3) enclose the result in quotes;
'* 4) append "cOPT";
'* 5) .Exec the resulting string.
'****
'*
Const cFOL = "d:\HP OpenView\bin\"
Const cCMD = "opcragt.cmd"
Const cOPT = " -status -all"
'*
Dim arrFOL
Dim intFOL
Dim strFOL
Dim strWSS
'*
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
arrFOL = Split(cFOL,"\")
strFOL = arrFOL(0)
For intFOL = 1 To UBound(arrFOL)
strFOL = strFOL & "\" & arrFOL(intFOL)
arrFOL(intFOL) = objFSO.GetFolder(strFOL).ShortName
Next
Set objFSO = Nothing
'*
strFOL = Join(arrFOL,"\") & "\"
strWSS = Chr(34) & strFOL & cCMD & Chr(34) & cOPT
WScript.Echo strWSS
Dim objWSS
Set objWSS = CreateObject("WScript.Shell")
Dim objCMD
Set objCMD = objWSS.Exec(strWSS)
WScript.Echo objCMD.StdErr.ReadAll
WScript.Echo objCMD.StdOut.ReadAll
Set objCMD = Nothing
Set objWSS = Nothing
'*
MsgBox "Done!",vbInformation,WScript.ScriptName
Will the value in "strWSS" work via Start+Run?
There may be better ways...
.
- References:
- Executing a command with options
- From: Warren
- Executing a command with options
- Prev by Date: Re: Other version information
- Next by Date: Re: vb script to detect if printer is installed and then install it from a list if not? (2003 server vbs)
- Previous by thread: Re: Executing a command with options
- Next by thread: Re: vb script to detect if printer is installed and then install it from a list if not? (2003 server vbs)
- Index(es):
Relevant Pages
|