CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 1998
    Posts
    1

    Unix type of filter program



    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




  2. #2
    Join Date
    Nov 1998
    Posts
    2

    Re: Unix type of filter program



    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured