Re: Executing a command with options



"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 using
the
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...



.



Relevant Pages

  • RE: Run a Stored Procedure from Excel
    ... You also want to find out if you have a rsDW variable defined. ... Your code had a semicolon between the 2nd command and the ... Dim cnnDW As ADODB.Connection ... Set cnnDW = New ADODB.Connection ...
    (microsoft.public.excel.programming)
  • RE: Run a Stored Procedure from Excel
    ... "You also want to find out if you have a rsDW variable defined. ... Your code had a semicolon between the 2nd command and the ... Dim cnnDW As ADODB.Connection ... Set cnnDW = New ADODB.Connection ...
    (microsoft.public.excel.programming)
  • RE: Open Access 2003 or 2007 from Excel
    ... 'EXAMPLE OF ACCESS COMMAND TO CONTROL FORMS ... 'Dim dbMain As ADODB.Connection ... 'Dim dbMain As ADODB.Connection 'compile error: ... new computers that now have VISTA as the OS. ...
    (microsoft.public.excel.programming)
  • Re: Multiple table in dataset query
    ... If a row is marked as Modified, it will run your query defined in the ... Update Command object. ... Dim UpdateStaffCmd As New OleDb.OleDbCommand ... Private Sub frmStaff_Load(ByVal sender As System.Object, ...
    (microsoft.public.dotnet.framework.adonet)
  • Tool to get MCP ODT at Windows CMD prompt
    ... You basically send a series of ODT commands of your choosing, once, or in a loop, and get the output right in the command ... Dim sHostname ... Sub WriteIt ... WriteIt "" ...
    (comp.sys.unisys)