Re: Shell Functions and DOS executables

Tech-Archive recommends: Speed Up your PC by fixing your registry



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
################################
.



Relevant Pages

  • Re: Shell Functions and DOS executables
    ... I downloaded the EXE, ... read the STDErrResults which is where you ... Reports "Error Converting filename.wfm" if NOT successful ... On Error GoTo KillCNVRTWFMError ...
    (microsoft.public.vb.general.discussion)
  • Re: Shell Functions and DOS executables
    ... Before you relocate the exe because of the short file name limitation of the ... ByVal lpszShortPath As String, _ ... Dim sShortPath As String ... Reports "Error Converting filename.wfm" if NOT successful ...
    (microsoft.public.vb.general.discussion)
  • Re: Mail::Sender problem
    ... I converted this script to exe using p2x-8.80-Win32.It gave warnings ... Config file missing. ... Did that really make a difference with respect to the config file ... problems while converting to exe before.Ofcourse I never used ...
    (comp.lang.perl.misc)
  • Re: Benefit of converting XLS to EXE ?
    ... downloaded the .exe file and run it. ... existing instance of Excel that I had loaded. ... I have converted an XLS file to EXE. ... disadvantages of converting XLS to EXE. ...
    (microsoft.public.excel)