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

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 619 Downloads 222

'Dos', 'cmd', 'command', 'output'

ANmarAmdeen
326
File System VBA
Revisions

v1.0