Re: Shell Functions and DOS executables



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.


"VB_Newby" <VB_Newby@xxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:43d1bb7e$0$38184$892e7fe2@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Lance Wynn said

> Click: Project --> References and then select Windows Script
> Host Object Model from the reference list.

Thanks!

I followed the above and the DOS command executes perfectly!

However, the "results" string remains null whether the DOS command
was successful or unsuccessful?

###################
Here's a code snippet:

If Option_TDS7104.Value = True Then
' Insert TDS7104 routine here
' strXXX = MsgBox("Not yet implemented", vbCritical)

Dim wsh As IWshRuntimeLibrary.WshShell
Dim wshExec As IWshRuntimeLibrary.wshExec
Dim results As String

'Copy CNVRTWFM to User Directory
FileCopy (App.Path & "\" & "CNVRTWFM.EXE"), (File1.Path &
"\" & "CNVRTWFM.EXE")

ChDir File1.Path 'Change to USER directory

'Create DOS command string
strDOSCOMMAND = "cnvrtwfm -l " & File1.filename

Set wsh = New WshShell
Set wshExec = wsh.Exec(strDOSCOMMAND)
results = wshExec.StdOut.ReadAll
Debug.Print "results = "; results

End If
###################

This seems similar to the result of my attempt to redirect the DOS
Command output to a text file.

cnvrtwfm -l tek00001.wfm > test.txt
(at the Command Prompt) yields an EMPTY file.

dir > test.txt
(at the Command Prompt) yields a dir-dump to test.txt

It's as if this ancient DOS file conversion utility
(http://www.tek.com/site/sw/detail/1,1059,464,00.html)
somehow prevents a redirect?
###############

Any ideas?

Regards,

VB_Newby

> "VB_Newby" <VB_Newby@xxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:43d192b4$0$51452$892e7fe2@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>>> "VB_Newby" <VB_Newby@xxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>>> news:43c05173$0$72436$892e7fe2
@authen.yellow.readfreenews.net...
>>>
>>> <Re-ordered for clarity>
>>>
>>> I'm running a DOS executable from a VB Shell function.
>>>
>>> If it's successful, it looks like this (at the DOS prompt):
>>> cnvrtwfm -l tek00001.wfm
>>> Creating tek00001.dat
>>>
>>>It it's unsuccessful, it looks like this (at the DOS prompt):
>>> cnvrtwfm -l tek00001.wfm
>>> Error Converting tek00001.wfm
>>>
>>> How can I retrieve the command line output of a Shell'ed DOS
>>> executable?
>
>> Lance Wynn said:
>> Hello,
>> Something along these lines may work for you.
>> (Make a reference in your project to the "Windows Script Host
>> Object Model")
>>
>> Dim wsh As IWshRuntimeLibrary.WshShell
>> Dim wshExec As IWshRuntimeLibrary.wshExec
>> Dim results as string
>> Set wsh = New WshShell
>> Set wshExec = wsh.Exec("c:\test.bat")
>> results = wshExec.StdOut.ReadAll
>
> Can someone further elaborate on how to integrate this into my VB
> program. I don't know how to "make a reference to a Windows
> Script Host Object Model". I'm just above clueless... but
> learning. ;-D
>
> (I tried redirecting the DOS command output via ">" but for some
> reason this silly DOS program won't be redirected to a file.)



.



Relevant Pages

  • Re: How to parse output from a command
    ... Dim RegEx, WSH ... Set WSH = CreateObject ... > bypass the DOS command all together, thinking there would be an easy way ...
    (microsoft.public.scripting.vbscript)
  • Re: combine two text files
    ... > that I can use to concatenate two files, ... I'd recommend using the DOS append command instead of the DOS Copy command, ... Dim sFileConcat As String ...
    (microsoft.public.access.modulesdaovba)
  • Re: getarg & 8.3 filename
    ... file and depend on file associations to launch the EXE, ... later versions) on the command line when lauching the EXE. ... I create a DOS 16 bit real mode EXE and make an icon for it, ... EXE to launch with the filename in the command tail. ...
    (comp.lang.fortran)
  • Re: Simple program not producing output
    ... Pasted the MSDN code into this code file. ... When to a command shell, located the exe. ... public static void PrintValues ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Simple program not producing output
    ... Pasted the MSDN code into this code file. ... When to a command shell, located the exe. ... public static void PrintValues ...
    (microsoft.public.dotnet.languages.csharp)