ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   DOS..BAT VB Progamming problem (https://www.excelbanter.com/excel-programming/439326-dos-bat-vbulletin-progamming-problem.html)

TOMD

DOS..BAT VB Progamming problem
 
I have a program that prints to the screen. From a DOS window, or with a BAT
file I can redirect the data to a file via the following command "Path Arg1
Arg2 Filename. But, when I execute the BAT file from a VB program, using
either Shell or FollowHyperlink, the output file is created or recreated but
remains empty. Any help will be greatly appreciated.

TomD

Steve Yandl[_3_]

DOS..BAT VB Progamming problem
 
Tom,

The example below is an example of a technique that might work for you. In
the example, I use the Exec method of the WScript.Shell object to capture
the output of a program that would typically print to the console screen (in
my example, I use ipconfig). The example simply reads the text stream
output line by line and places the output in Column A of the active sheet
but you could easily use the filesystemobject to create a new text file
somewhere with the contents of the output if that's your ultimate goal.

Steve Yandl

'------------------------------------
Sub FetchIPconfig()

Dim r As Integer
r = 1

Set objShell = CreateObject("Wscript.Shell")
Set objWshExec = objShell.Exec("ipconfig")
Set objStdOut = objWshExec.StdOut

Do Until objStdOut.AtEndOfStream
strLine = objStdOut.ReadLine
Cells(r, 1).Value = strLine
r = r + 1
Loop

Columns("A:A").EntireColumn.AutoFit

Set objStdOut = Nothing
Set objWshExec = Nothing
Set objShell = Nothing
End Sub


'-------------------------------------


"TomD" wrote in message
...
I have a program that prints to the screen. From a DOS window, or with a
BAT
file I can redirect the data to a file via the following command "Path
Arg1
Arg2 Filename. But, when I execute the BAT file from a VB program, using
either Shell or FollowHyperlink, the output file is created or recreated
but
remains empty. Any help will be greatly appreciated.

TomD



Rick Rothstein

DOS..BAT VB Progamming problem
 
This is only a guess, but try adding a call to the Command Processor in your
Shell statement, something like this...

Shell Environ("COMSPEC") & " c:\Path\To\BatFile\NameOfBatFile.bat"

Note the space in front of the path string.

--
Rick (MVP - Excel)


"TomD" wrote in message
...
I have a program that prints to the screen. From a DOS window, or with a
BAT
file I can redirect the data to a file via the following command "Path
Arg1
Arg2 Filename. But, when I execute the BAT file from a VB program, using
either Shell or FollowHyperlink, the output file is created or recreated
but
remains empty. Any help will be greatly appreciated.

TomD



TOMD

DOS..BAT VB Progamming problem
 
HI guys,

Thanks for the help.

I have found a partial solution to my problem as shown below:

varProc = Shell("cmd /c c:\Program.exe arg1 arg2 c:\InputData.txt")

But, the problem is that the Executable will not always be in a Root
Directory, as different people will put it in different places. It is,
however, explicitively implied that it be in the same directory as the
WorkBook.

Therefore I tried this method and it fails:

FileName = ActiveWorkbook.Path & "\Program.exe arg1 arg2 c:\InputData.txt"

Thanks in advance for any help that you can give me,
Tom



"TomD" wrote:

I have a program that prints to the screen. From a DOS window, or with a BAT
file I can redirect the data to a file via the following command "Path Arg1
Arg2 Filename. But, when I execute the BAT file from a VB program, using
either Shell or FollowHyperlink, the output file is created or recreated but
remains empty. Any help will be greatly appreciated.

TomD


TOMD

DOS..BAT VB Progamming problem
 
Whoops, I forgot to show the resulting command, whic is as follows:

varProc = Shell("cmd /c FileName")


"TomD" wrote:

HI guys,

Thanks for the help.

I have found a partial solution to my problem as shown below:

varProc = Shell("cmd /c c:\Program.exe arg1 arg2 c:\InputData.txt")

But, the problem is that the Executable will not always be in a Root
Directory, as different people will put it in different places. It is,
however, explicitively implied that it be in the same directory as the
WorkBook.

Therefore I tried this method and it fails:

FileName = ActiveWorkbook.Path & "\Program.exe arg1 arg2 c:\InputData.txt"

Thanks in advance for any help that you can give me,
Tom



"TomD" wrote:

I have a program that prints to the screen. From a DOS window, or with a BAT
file I can redirect the data to a file via the following command "Path Arg1
Arg2 Filename. But, when I execute the BAT file from a VB program, using
either Shell or FollowHyperlink, the output file is created or recreated but
remains empty. Any help will be greatly appreciated.

TomD



All times are GMT +1. The time now is 01:20 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com