Re: Shell Functions and DOS executables
- From: "VB_Newby" <VB_Newby@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: 22 Jan 2006 02:50:19 GMT
Lance Wynn said
> That's interesting. I downloaded the EXE, and while I can't pass
> it a valid file, I was able to retrieve output from it, albeit in
> a round about way ;-)
>
> I had to create a .BAT file that actually made the call to the
> exe, the .BAT file only needs one line:
> D:\temp\cnvrtwfm.exe %*
>
> (or it's equivalent)
>
> Then, I run the BAT file just like I would the exe, but I tweaked
> the code a bit to read the STDErr as well. Read the STDOut into
> a variable, which will show you the output from the BAT, and
> immediately following, read the STDErrResults which is where you
> should see the output from the exe. Now, I believe the
> STDOut.ReadAll call will not complete until the BAT file exits,
> which is not until the exe finishes processing, so you should be
> ok, but you may need to put a loop in there to check for
> completion:
>
> Dim wsh As IWshRuntimeLibrary.WshShell
> Dim wshExec As IWshRuntimeLibrary.wshExec
> Dim STDErrResults As String
> Dim STDOutResults As String
> Set wsh = New WshShell
> 'Set wshExec = wsh.Exec("D:\temp\cnvrtwfm.exe")
> Set wshExec = wsh.Exec("C:\test.bat fdsfs -p -r -blah")
> STDOutResults = wshExec.StdOut.ReadAll
>
>
> STDErrResults = wshExec.StdErr.ReadAll
>
>
> BTW, I'd love to hear if this works for you.
Success!
STDOutResults
Reports (echo's) the command string whether the CNVRTWFM.EXE
succeeds or fails. Example: "cnvrtwfm.exe -l TEK00009.wfm"
STDErrResults
Reports "Creating filename.dat" if successful
(Example: Creating TEK00009.dat)
Reports "Error Converting filename.wfm" if NOT successful
(Example: Error Converting TEK00009.wfm)
So, I interrogate STDErrResults for "Error", Presto!
Next step: Now, I'm integrating yet another Tektronix conversion
program (ConvertTekWfm.exe). This animal is much more verbose,
doesn't need to be wrapped in a batch file, and reports ALL it's
info via the STDOutResults. Go figure? ;-D
Thanks again for all your help. I'd have never figured this out!
Code Snippet:
################################
If Option_TDS754C.Value = True Then
' Well this stinks.
' Apparently the TEK CNVRTWFM file cannot handle directories longer
' than 8 chars! So, copy the CNVRTWFM file to USER directory, do
' conversion, delete it, Ugh..... How crude is this?
FileCopy (App.Path & "\" & "cnvrtwfm.exe"), _
(File1.Path & "\" & "cnvrtwfm.exe")
FileCopy (App.Path & "\" & "cnvrtwfm.bat"), _
(File1.Path & "\" & "cnvrtwfm.bat")
ChDir File1.Path 'USER dir
strDOSCOMMAND = "cnvrtwfm.bat -l " & File1.filename
Set wsh = New WshShell
Set wshExec = wsh.Exec(strDOSCOMMAND)
STDOutResults = wshExec.StdOut.ReadAll
'Copy of command string ("cnvrtwfm.exe -l TEK00009.wfm")
STDErrResults = wshExec.StdErr.ReadAll
'"Creating TEK00009.dat" if successful
'"Error Converting TEK00009.dat" if failure
On Error GoTo KillCNVRTWFMError
Kill "CNVRTWFM.*" 'Death to both EXE and BATT
If Left(STDErrResults, 5) <> "Error" Then
' Oddly enough, the TEK converter outputs a text file called .DAT?
' This .DAT file needs renamed to .txt - lest it be confused with
' a MathCad .DAT file
' Build string of .DAT filename,
' Build string of destination filename (.txt)
strSource = (Left(File1.filename, (Len(File1.filename) - 4))) &
".dat"
strDest = File1.Path & "\" & NewFileName
On Error GoTo CopyDatToTxtError
FileCopy strSource, strDest 'Copy .DAT to .TXT
On Error GoTo KillSourceError
Kill strSource 'Delete the .DAT file
Else
GoTo CNVRTWFM_Error 'Conversion error
End If
################################
.
- Follow-Ups:
- Re: Shell Functions and DOS executables
- From: Randy Birch
- Re: Shell Functions and DOS executables
- From: Lance Wynn
- Re: Shell Functions and DOS executables
- References:
- Shell Functions and DOS executables
- From: VB_Newby
- Re: Shell Functions and DOS executables
- From: Lance Wynn
- Re: Shell Functions and DOS executables
- From: VB_Newby
- Re: Shell Functions and DOS executables
- From: Lance Wynn
- Re: Shell Functions and DOS executables
- From: VB_Newby
- Re: Shell Functions and DOS executables
- From: Lance Wynn
- Shell Functions and DOS executables
- Prev by Date: Re: Multiple clipboards?
- Next by Date: Help with Richtextbox
- Previous by thread: Re: Shell Functions and DOS executables
- Next by thread: Re: Shell Functions and DOS executables
- Index(es):
Relevant Pages
|