stdout -- Why is it so hard?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 15 of 15

Thread: stdout -- Why is it so hard?

  1. #1
    Joe Shields Guest

    stdout -- Why is it so hard?


    So I am trying to pass a value back to stdout after executing a VB application
    with command switches from command line. Although it appears to get a valid
    handle, nothing is returned to the shell session.

    Here is what I am doing.....

    Option Explicit

    Public Const STD_OUTPUT_HANDLE = -11&

    Public Declare Function w32_stdout Lib "kernel32" Alias "GetStdHandle" _
    (Optional ByVal Handletype As Long = STD_OUTPUT_HANDLE) As Long

    Public Declare Function WriteFile Lib "kernel32" _
    (ByVal hFile As Long, ByVal lpBuffer As Any, ByVal nNumberOfBytesToWrite
    As Long, _
    lpNumberOfBytesWritten As Long, Optional ByVal lpOverlapped As Long = 0&)
    As Long

    Public Function stdout()

    Dim sWriteBuffer As String
    Dim lBytesWritten As Long
    Dim hStdOut As Long


    'Send something to stdout
    sWriteBuffer = "This really sucks!" & vbCrLf
    hStdOut = w32_stdout()
    WriteFile hStdOut, sWriteBuffer, Len(sWriteBuffer) + 1, lBytesWritten



    End Function

    Any suggestions on how to return a value to the command line via stdout or
    another method? I hate to say it but in C this is cake. Why does it have
    to be so hard in VB.

    Thanks!

  2. #2
    Monte Hansen Guest

    Re: stdout -- Why is it so hard?


    http://www.win2000mag.com/Articles/I...cleID=565&pg=1

    +|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+
    Monte Hansen
    http://KillerVB.com
    +|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+



    "Joe Shields" <joe.shields@wellsfargo.com> wrote:
    >
    >So I am trying to pass a value back to stdout after executing a VB application
    >with command switches from command line. Although it appears to get a valid
    >handle, nothing is returned to the shell session.
    >
    >Here is what I am doing.....
    >
    >Option Explicit
    >
    >Public Const STD_OUTPUT_HANDLE = -11&
    >
    >Public Declare Function w32_stdout Lib "kernel32" Alias "GetStdHandle" _
    >(Optional ByVal Handletype As Long = STD_OUTPUT_HANDLE) As Long
    >
    >Public Declare Function WriteFile Lib "kernel32" _
    >(ByVal hFile As Long, ByVal lpBuffer As Any, ByVal nNumberOfBytesToWrite
    >As Long, _
    >lpNumberOfBytesWritten As Long, Optional ByVal lpOverlapped As Long = 0&)
    >As Long
    >
    >Public Function stdout()
    >
    >Dim sWriteBuffer As String
    >Dim lBytesWritten As Long
    >Dim hStdOut As Long
    >
    >
    >'Send something to stdout
    >sWriteBuffer = "This really sucks!" & vbCrLf
    >hStdOut = w32_stdout()
    >WriteFile hStdOut, sWriteBuffer, Len(sWriteBuffer) + 1, lBytesWritten
    >
    >
    >
    >End Function
    >
    >Any suggestions on how to return a value to the command line via stdout

    or
    >another method? I hate to say it but in C this is cake. Why does it have
    >to be so hard in VB.
    >
    >Thanks!



  3. #3
    Monte Hansen Guest

    Re: stdout -- Why is it so hard?


    http://www.win2000mag.com/Articles/I...cleID=565&pg=1

    +|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+
    Monte Hansen
    http://KillerVB.com
    +|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+



    "Joe Shields" <joe.shields@wellsfargo.com> wrote:
    >
    >So I am trying to pass a value back to stdout after executing a VB application
    >with command switches from command line. Although it appears to get a valid
    >handle, nothing is returned to the shell session.
    >
    >Here is what I am doing.....
    >
    >Option Explicit
    >
    >Public Const STD_OUTPUT_HANDLE = -11&
    >
    >Public Declare Function w32_stdout Lib "kernel32" Alias "GetStdHandle" _
    >(Optional ByVal Handletype As Long = STD_OUTPUT_HANDLE) As Long
    >
    >Public Declare Function WriteFile Lib "kernel32" _
    >(ByVal hFile As Long, ByVal lpBuffer As Any, ByVal nNumberOfBytesToWrite
    >As Long, _
    >lpNumberOfBytesWritten As Long, Optional ByVal lpOverlapped As Long = 0&)
    >As Long
    >
    >Public Function stdout()
    >
    >Dim sWriteBuffer As String
    >Dim lBytesWritten As Long
    >Dim hStdOut As Long
    >
    >
    >'Send something to stdout
    >sWriteBuffer = "This really sucks!" & vbCrLf
    >hStdOut = w32_stdout()
    >WriteFile hStdOut, sWriteBuffer, Len(sWriteBuffer) + 1, lBytesWritten
    >
    >
    >
    >End Function
    >
    >Any suggestions on how to return a value to the command line via stdout

    or
    >another method? I hate to say it but in C this is cake. Why does it have
    >to be so hard in VB.
    >
    >Thanks!



  4. #4
    Joe Shields Guest

    Re: stdout -- Why is it so hard?


    This article is essentially a regurgitation of Q239588. The problem is that
    it doesn't actually write back to the shell. If you take the code provided
    in the article... it doesn't return anything to the shell. If it is calling
    a new command shell then it can do it no problem. It looks like the problem
    is obtaining the valid handle. Still not sure what to do.


    Thanks!

    Joe

    "Monte Hansen" <monte@nospam.com> wrote:
    >
    >http://www.win2000mag.com/Articles/I...cleID=565&pg=1
    >
    >+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+
    >Monte Hansen
    >http://KillerVB.com
    >+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+
    >
    >
    >
    >"Joe Shields" <joe.shields@wellsfargo.com> wrote:
    >>
    >>So I am trying to pass a value back to stdout after executing a VB application
    >>with command switches from command line. Although it appears to get a valid
    >>handle, nothing is returned to the shell session.
    >>
    >>Here is what I am doing.....
    >>
    >>Option Explicit
    >>
    >>Public Const STD_OUTPUT_HANDLE = -11&
    >>
    >>Public Declare Function w32_stdout Lib "kernel32" Alias "GetStdHandle"

    _
    >>(Optional ByVal Handletype As Long = STD_OUTPUT_HANDLE) As Long
    >>
    >>Public Declare Function WriteFile Lib "kernel32" _
    >>(ByVal hFile As Long, ByVal lpBuffer As Any, ByVal nNumberOfBytesToWrite
    >>As Long, _
    >>lpNumberOfBytesWritten As Long, Optional ByVal lpOverlapped As Long = 0&)
    >>As Long
    >>
    >>Public Function stdout()
    >>
    >>Dim sWriteBuffer As String
    >>Dim lBytesWritten As Long
    >>Dim hStdOut As Long
    >>
    >>
    >>'Send something to stdout
    >>sWriteBuffer = "This really sucks!" & vbCrLf
    >>hStdOut = w32_stdout()
    >>WriteFile hStdOut, sWriteBuffer, Len(sWriteBuffer) + 1, lBytesWritten
    >>
    >>
    >>
    >>End Function
    >>
    >>Any suggestions on how to return a value to the command line via stdout

    >or
    >>another method? I hate to say it but in C this is cake. Why does it have
    >>to be so hard in VB.
    >>
    >>Thanks!

    >



  5. #5
    Joe Shields Guest

    Re: stdout -- Why is it so hard?


    This article is essentially a regurgitation of Q239588. The problem is that
    it doesn't actually write back to the shell. If you take the code provided
    in the article... it doesn't return anything to the shell. If it is calling
    a new command shell then it can do it no problem. It looks like the problem
    is obtaining the valid handle. Still not sure what to do.


    Thanks!

    Joe

    "Monte Hansen" <monte@nospam.com> wrote:
    >
    >http://www.win2000mag.com/Articles/I...cleID=565&pg=1
    >
    >+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+
    >Monte Hansen
    >http://KillerVB.com
    >+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+
    >
    >
    >
    >"Joe Shields" <joe.shields@wellsfargo.com> wrote:
    >>
    >>So I am trying to pass a value back to stdout after executing a VB application
    >>with command switches from command line. Although it appears to get a valid
    >>handle, nothing is returned to the shell session.
    >>
    >>Here is what I am doing.....
    >>
    >>Option Explicit
    >>
    >>Public Const STD_OUTPUT_HANDLE = -11&
    >>
    >>Public Declare Function w32_stdout Lib "kernel32" Alias "GetStdHandle"

    _
    >>(Optional ByVal Handletype As Long = STD_OUTPUT_HANDLE) As Long
    >>
    >>Public Declare Function WriteFile Lib "kernel32" _
    >>(ByVal hFile As Long, ByVal lpBuffer As Any, ByVal nNumberOfBytesToWrite
    >>As Long, _
    >>lpNumberOfBytesWritten As Long, Optional ByVal lpOverlapped As Long = 0&)
    >>As Long
    >>
    >>Public Function stdout()
    >>
    >>Dim sWriteBuffer As String
    >>Dim lBytesWritten As Long
    >>Dim hStdOut As Long
    >>
    >>
    >>'Send something to stdout
    >>sWriteBuffer = "This really sucks!" & vbCrLf
    >>hStdOut = w32_stdout()
    >>WriteFile hStdOut, sWriteBuffer, Len(sWriteBuffer) + 1, lBytesWritten
    >>
    >>
    >>
    >>End Function
    >>
    >>Any suggestions on how to return a value to the command line via stdout

    >or
    >>another method? I hate to say it but in C this is cake. Why does it have
    >>to be so hard in VB.
    >>
    >>Thanks!

    >



  6. #6
    Peter Young Guest

    Re: stdout -- Why is it so hard?

    > Any suggestions on how to return a value to the command line via stdout or
    > another method? I hate to say it but in C this is cake. Why does it have
    > to be so hard in VB.


    Because in C you are creating a console application, and in VB you are creating a windows
    application.

    After compiling your windows app, you can run editbin.exe with the /subsystem:console
    switch on your binary to turn it into a console app. Your stdout functionality should work
    as expected.

    Regards,

    Pete Young



  7. #7
    Peter Young Guest

    Re: stdout -- Why is it so hard?

    > Any suggestions on how to return a value to the command line via stdout or
    > another method? I hate to say it but in C this is cake. Why does it have
    > to be so hard in VB.


    Because in C you are creating a console application, and in VB you are creating a windows
    application.

    After compiling your windows app, you can run editbin.exe with the /subsystem:console
    switch on your binary to turn it into a console app. Your stdout functionality should work
    as expected.

    Regards,

    Pete Young



  8. #8
    Joe Shields Guest

    Re: stdout -- Why is it so hard?


    Mr. Young... you rock!

    Worked perfectly!

    BTW, is this what happens behind the scene when you make a conssole application
    in VC++?

    Joe

    "Peter Young" <TubeCrunch@telocity.com.nospam> wrote:
    >> Any suggestions on how to return a value to the command line via stdout

    or
    >> another method? I hate to say it but in C this is cake. Why does it have
    >> to be so hard in VB.

    >
    >Because in C you are creating a console application, and in VB you are creating

    a windows
    >application.
    >
    >After compiling your windows app, you can run editbin.exe with the /subsystem:console
    >switch on your binary to turn it into a console app. Your stdout functionality

    should
    >work
    >as expected.
    >
    >Regards,
    >
    >Pete Young
    >
    >



  9. #9
    Joe Shields Guest

    Re: stdout -- Why is it so hard?


    Mr. Young... you rock!

    Worked perfectly!

    BTW, is this what happens behind the scene when you make a conssole application
    in VC++?

    Joe

    "Peter Young" <TubeCrunch@telocity.com.nospam> wrote:
    >> Any suggestions on how to return a value to the command line via stdout

    or
    >> another method? I hate to say it but in C this is cake. Why does it have
    >> to be so hard in VB.

    >
    >Because in C you are creating a console application, and in VB you are creating

    a windows
    >application.
    >
    >After compiling your windows app, you can run editbin.exe with the /subsystem:console
    >switch on your binary to turn it into a console app. Your stdout functionality

    should
    >work
    >as expected.
    >
    >Regards,
    >
    >Pete Young
    >
    >



  10. #10
    Peter Young Guest

    Re: stdout -- Why is it so hard?

    > Mr. Young... you rock!

    Well, I used to, but now I just write code. :-)

    > BTW, is this what happens behind the scene when you make a conssole application
    > in VC++?


    Yep.

    -Pete



  11. #11
    Peter Young Guest

    Re: stdout -- Why is it so hard?

    > Mr. Young... you rock!

    Well, I used to, but now I just write code. :-)

    > BTW, is this what happens behind the scene when you make a conssole application
    > in VC++?


    Yep.

    -Pete



  12. #12
    L.J. Johnson Guest

    Re: stdout -- Why is it so hard?

    Joe,

    > So I am trying to pass a value back to stdout after executing a VB

    application
    > with command switches from command line. Although it appears to get a

    valid
    > handle, nothing is returned to the shell session.


    If you want a complete code example of how to create a console app in VB,
    look at my web site (below)... It has code for an article I did for VBPJ.
    With a few extra lines of code (examples given), you can also have your VB
    console app do redirection and piping.

    --
    L.J. Johnson, Slightly Tilted Software
    Microsoft MVP (Visual Basic)
    LJJohnson@SlightlyTiltedSoftware.com or LJJohnson@mvps.org
    <http://www.SlightlyTiltedSoftware.com>
    Ask The NT Pro at <http://www.devx.com/gethelp>




  13. #13
    L.J. Johnson Guest

    Re: stdout -- Why is it so hard?

    Joe,

    > So I am trying to pass a value back to stdout after executing a VB

    application
    > with command switches from command line. Although it appears to get a

    valid
    > handle, nothing is returned to the shell session.


    If you want a complete code example of how to create a console app in VB,
    look at my web site (below)... It has code for an article I did for VBPJ.
    With a few extra lines of code (examples given), you can also have your VB
    console app do redirection and piping.

    --
    L.J. Johnson, Slightly Tilted Software
    Microsoft MVP (Visual Basic)
    LJJohnson@SlightlyTiltedSoftware.com or LJJohnson@mvps.org
    <http://www.SlightlyTiltedSoftware.com>
    Ask The NT Pro at <http://www.devx.com/gethelp>




  14. #14
    Matthew Curland Guest

    Re: stdout -- Why is it so hard?

    This won't help you with the code (you've gotten plenty of help on that),
    but it will help you with the build process.

    This request comes in often enough that I figured I would put together an
    add-in to do the equivalent of the EditBin step. No fancy UI, but it works
    great for either a Make Exe or a command line build, and you don't need a
    separate EditBin step.

    http://www.PowerVB.com/ConsoleApp.htm

    -Matt





  15. #15
    Matthew Curland Guest

    Re: stdout -- Why is it so hard?

    This won't help you with the code (you've gotten plenty of help on that),
    but it will help you with the build process.

    This request comes in often enough that I figured I would put together an
    add-in to do the equivalent of the EditBin step. No fancy UI, but it works
    great for either a Make Exe or a command line build, and you don't need a
    separate EditBin step.

    http://www.PowerVB.com/ConsoleApp.htm

    -Matt





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center