Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VB cmd line exe to output results in DOS window (VB6)

    Now this one has to be doable, but I can't seem to find it. All I want to do is create a standard exe in VB and print a line to the console. In otherwords I want the output to appear in the DOS box that I launch the .exe from. For example:

    c:>vbapp.exe <Press enter>
    c:>This is a line printed from the VB app.

    One would think this would be a pretty easy thing to do, but I can't find it. Only writing to files or forms or debug.

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB cmd line exe to output results in DOS windo

    What happens if you write the data to a file called "CON"?

    There are a few other DOS words I recall, LPT1, PRN, LPT2 and so on.

    I had/have a copy of VB6 lying around soemwhere. Are you using that or its equivalent when you say "VB?"

  3. #3
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: VB cmd line exe to output results in DOS window (VB6)

    In DOS command window you'd use ECHO command to write text to the console screen. Example of a one-line batch file:

    cmd.exe /k echo "Hello Stupid"

    When runs, opens a command window and writes text one line below the command executed. As for doing this in VB, the following MSKB article has an example of a simple VB app that "demonstrates attaching a console window to your Visual Basic application, writing to it, and running another application in the console window." See MSKB Art 171654:

    HOWTO: Attach a Console Window to Your Visual Basic Program

    The article notes: "If a Visual Basic application is started from a console application, the operating system automatically detaches it from the console, preventing the Visual Basic application from interacting with it. This article does not provide a method to prevent this from happening, but does demonstrate creating a new console window that your application can interact with. It also demonstrates running a console application (batch file, in this case) from Visual Basic, which utilizes the created console."

    Various Windows API functions are used for this (for example, WriteConsole writes text output to console window). As test, compiled a simple VB6 .exe using code from MSKB article, and using the batch file above for test purposes. See attached pic for example of result when running the compiled .exe file.

    This may or may not be exactly what you are looking for, but may provide some clues on how to go about doing this in VB.

    HTH

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: VB cmd line exe to output results in DOS window (VB6)

    As a footnote, Michael Brook has an article in the February 2004 edition of MSDN Magazine entitled "Console Applications in .NET, or Teaching a New Dog Old Tricks." I don't see any VB/COM code in the article, though, it appears to be C# and .NET all the way through.

  5. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB cmd line exe to output results in DOS window (VB6)

    Mark, this is a little late but I wanted to thank you for your reply - this resolved our issue perfectly. Thanks again.

Posting Permissions

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