DosCommand_Read

Get output of DOS Command in string, by reading output into temp text file, then read that file back into string.
Can be used to run any command, using > symbol

CodeFunctionName
What is this?

Public

Tested

Original Work
Function DosCommand_Read(DOSCommand, TempFile)
' Gets the out put of a dos command
' Any dos command
Dim iFile As Integer
Dim sData As String
iFile = FreeFile()
FullDOSCommand = ""
File2 = TempFile
IF File2 = "" then File2 = "C:\File1.txt"
Shell "cmd /c " & DOSCommand & " > " & File2
DoEvents
Do ' wait for it to finish ...
DoEvents
On Error Resume Next
Close #iFile
Open File2 For Input As #iFile
If Err.Number = 0 Then Exit Do
Loop
Close #iFile
On Error GoTo 0
Open File2 For Input As #iFile
sData = Input(LOF(iFile), #iFile)
Close #iFile
DoEvents
Kill File2
DosCommand_Read = sData
End Function

DOSCommand, TempFile

Views 4,356

Downloads 1,317

CodeID
DB ID

ANmarAmdeen
610
Revisions

v1.0

Friday
June
22
2018