'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' First method reads STDOUT directly
' Uses exec, unavoidable cmd blip
Set WSH = New WshShell
Set oExec = WSH.Exec("cmd /C findstr " & spattern & Space(1) & File_in)
Set oOutput = oExec.StdOut
Dim s As String
Dim sLine As String
While Not oOutput.AtEndOfStream
sLine = oOutput.ReadLine
If sLine <> "" Then s = s & sLine & vbCrLf
Wend
Find_Line = s
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' First method reads STDOUT through a temporary file and deletes it
' Uses run, avoidable cmd blip
Dim cmdCommand As String
Dim strOutput
'cmdCommand = "cmd.exe /C findstr " & spattern & Space(1) & File_in & " > C:\out.txt"
'MsgBox (cmdCommand)
With CreateObject("WScript.Shell")
'.Run "cmd /C findstr " & spattern & Space(1) & File_in & " > C:\Users\p.doulgeridis\Desktop\out.txt", 0, True
.Run "cmd /C findstr " & spattern & Space(1) & File_in & " > " & TempDir, 0, True
End With
With CreateObject("Scripting.FileSystemObject")
strOutput = .OpenTextFile("C:\Users\p.doulgeridis\Desktop\out.txt").ReadAll()
.DeleteFile "C:\Users\p.doulgeridis\Desktop\out.txt"
End With
Find_Line_nocmd = strOutput
Public Function Find_Line_nocmd(spattern As String, File_in As String) As String
' Function : Find_Line_nocmd
' Work : Check a specific file for a line and print it, no cmd window
' Called as: Find_Line_nocmd(string, /path/to/file)
' Called at: Main Form Find Line Button
' Input : string to be checked, file_in (path)
' Notes : This is the one actually used in main form.
' Construct command line
Dim cmdCommand As String
Dim strOutput
'cmdCommand = "cmd.exe /C findstr " & spattern & Space(1) & File_in & " > C:\out.txt"
'MsgBox (cmdCommand)
With CreateObject("WScript.Shell")
'.Run "cmd /C findstr " & spattern & Space(1) & File_in & " > C:\Users\p.doulgeridis\Desktop\out.txt", 0, True
.Run "cmd /C findstr " & spattern & Space(1) & File_in & " > " & TempDir, 0, True
End With
With CreateObject("Scripting.FileSystemObject")
strOutput = .OpenTextFile("C:\Users\p.doulgeridis\Desktop\out.txt").ReadAll()
.DeleteFile "C:\Users\p.doulgeridis\Desktop\out.txt"
End With
Find_Line_nocmd = strOutput
End Function
Public Function Find_Line(spattern As String, File_in As String) As String
' This version blips cmd
' Function : Find_Line
' Work : Check a specific file for a line and print it
' Called as: Find_Line(string, /path/to/file)
' Called at: Main Form Find Line Button
' Input : string to be checked, file_in (path)
Dim WSH As WshShell
Dim oExec As Object
Dim oOutput As Object
Set WSH = New WshShell
Set oExec = WSH.Exec("cmd /C findstr " & spattern & Space(1) & File_in)
Set oOutput = oExec.StdOut
Dim s As String
Dim sLine As String
While Not oOutput.AtEndOfStream
sLine = oOutput.ReadLine
If sLine <> "" Then s = s & sLine & vbCrLf
Wend
Find_Line = s
' This does not blip cmd
'Set oExec = WSH.Run("cmd /C findstr " & spattern & Space(1) & File_in & " > C:\Users\p.doulgeridis\Desktop\out.txt", 0, True
'Dim resp As String
'resp = redirect(StdOut)
'S = resp
'S = StdOut.ReadLine
'Do Until StdOut.AtEndOfStream
' S = S & vbCrLf & StdOut.ReadLine
'Loop
'MsgBox (S)
'Find_Line = S
End Function