Click to See Complete Forum and Search --> : Unix type of filter program


Pekka Levanen
October 26th, 1998, 01:46 PM
What I'm trying to do is a Unix type command line filter program to read stdin and output to stdout i.e. c:\temp\dir | myfilter | more


Any help is greatly appreciated


thanks

Al Lopez
November 24th, 1998, 09:15 AM
Having the same problem. I'm able to dump stdout to a console. But I need to dump it to a text file too.


The following sample comes from Microsoft.


Option Explicit

Dim hConsole As Long


Private Sub Command1_Click()

Dim Result As Long, sOut As String, cWritten As Long



sOut = "Hello World, testing STDOUT" & vbCrLf

Result = WriteConsole(hConsole, ByVal sOut, Len(sOut), _

cWritten, ByVal 0&)



Shell "C:\temp\test1.bat"

'Shell "C:\ORAWIN95\BIN\R25RUN32.EXE CMDFILE=c:\soe_ems\VO_PLPR_UPDTE.cmd"

Text1.Text = WriteConsole(hConsole, ByVal sOut, Len(sOut), _

cWritten, ByVal 0&)






'Dim Handle As Integer

'Dim FileString As String

'Handle = FreeFile

'Open "C:\TEMP\TST.TXT" For Binary As #Handle

'FileString = Space(FileLen("C:\TEMP\TST.TXT"))

'Get #Handle, , FileString

'Close #Handle




End Sub


Private Sub Command2_Click()



Dim Result As Long, sOut As String, cWritten As Long

Dim TestStd



sOut = "Hello World, testing STDOUT" & vbCrLf

Result = WriteConsole(hConsole, ByVal sOut, Len(sOut), _

cWritten, ByVal 0&)



'Shell "C:\temp\test.bat"

TestStd = Shell("C:\temp\test.bat > c:\temp\test.out", 1)

'Shell "C:\temp\test.bat"

'Shell "C:\ORAWIN95\BIN\PLUS33W.EXE ops$soe/soesoe@t:kaley:SOE @c:\temp\test_sql.sql"

Text1.Text = WriteConsole(hConsole, ByVal sOut, Len(sOut), _

cWritten, ByVal 0&)

End Sub


Private Sub Form_Load()



If AllocConsole() Then

hConsole = GetStdHandle(STD_OUTPUT_HANDLE)

If hConsole = 0 Then

MsgBox "Could not allocate STDOUT"

End If

Else

MsgBox "Could not allocate console"

End If



End Sub


Private Sub Form_Unload(Cancel As Integer)

CloseHandle hConsole

FreeConsole

End Sub


++++++++++++++++++++++++++++++++++++++++++++++++++++++

Need to the following module


Option Explicit


Declare Function AllocConsole Lib "kernel32" () As Long

Declare Function FreeConsole Lib "kernel32" () As Long

Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) As Long

Declare Function WriteConsole Lib "kernel32" Alias "WriteConsoleA" _

(ByVal hConsoleOutput As Long, lpBuffer As Any, ByVal _

nNumberOfCharsToWrite As Long, lpNumberOfCharsWritten As Long, _

lpReserved As Any) As Long


Public Const STD_OUTPUT_HANDLE = -11&


+++++++++++++++++++++++++++++++++++++++++++


Please keep me posted.