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

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » VB cmd line exe to output results in DOS window (VB6)

    Author
    Topic
    #398597

    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
    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.

    Viewing 5 reply threads
    Author
    Replies
    • #763500

      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?”

    • #763501

      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?”

    • #763659

      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

      • #777329

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

      • #777330

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

    • #763660

      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

    • #769557

      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.

    • #769558

      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.

    Viewing 5 reply threads
    Reply To: VB cmd line exe to output results in DOS window (VB6)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: