Question : Can I read the stdout from a Shell() call back into VBA?

I want to run a batch file that outputs some text to stdout.  I want to read the stdout text and change the program flow in my VBA code based on the contents of the text.  How can I read stdout?

Answer : Can I read the stdout from a Shell() call back into VBA?

The only way to do this is to pipe the stdout to a file and then read the file. It's actually quite easy. Here is a simple function to read a file into a string variable:

Public Function GetResults(ByVal FilePathName As String) As String

   Dim FileNumber As Long

   FileNumber = FreeFile

   On Error GoTo GetResults_Exit
   Open FilePathName For Input As FileNumber
   
   Input #FileNumber, GetResults
   
   Close FileNumber
   
GetResults_Exit:

End Function

Kevin
Random Solutions  
 
programming4us programming4us