Can C++Builder Form Application wait until termination on command prompt ?

Posted on 2014-08-06
Last Modified: 2014-08-06
Hello Experts,

C++Builder XE5, Windows 7 64bit

When I run C++Builder Form Application on command prompt, it returns immediately without waiting its termination.
I want to show some messages with fprintf(stderr or stdout) in my form application, but I don't know how to setup my form application.

Any hints welcome,
Nobuo Miwa
Question by:NobMiwa
    LVL 24

    Expert Comment

    You can "wait" for the program completion in the batch files using one of the following methods:
    START /wait notepad.exe 

    Open in new window

    CALL notepad.exe 

    Open in new window

    Both of these commands will wait for the program to complete before proceeding to the next line.
    If you call the program on its own, like this:

    Open in new window

    The next line in the batch file will be executed immediately.
    (NB: replace notepad.exe with the name and path of your program)
    LVL 86

    Expert Comment

    If you are creating a Windows GUI application (which I presume), there simply is no stdout or stderr. What you can do to display diagnostic information is using 'OutputDebugString()' ( and watch the output e.g. using "DebugView" (

    Alternatively you can of course wite your diagnostic output to a file using 'fprintf()', but I prefer the lhat method.

    Author Comment

    Thanks quick advice,

    I tried both, but that could not print string from printf("hello\n").
    I want to print it in command prompt.

    Nobuo Miwa
    LVL 86

    Assisted Solution

    Again: When you are launching a GUI application, there is no command prompt. At least none related to that application. GUI apps just detach from command prompts, see the docs on 'CreateProcess()' (
    LVL 24

    Accepted Solution

    I think you need to read this article. It is a little bit dated, but in my opinion still relevant. The idea described in this article is to use a project for the console application and just create the Windows Form. The piece of code that creates the form in the console application is closer to the end of this article:
            // Create an instance of the TForm
            // class and show the form.
            TForm1* Form1 = new TForm1(0);
            int x = Form1->ShowModal();
            // Enable the console window and
            // bring it to the top.
            EnableWindow(hWnd, true);
            // Display the results of the modal form.
            cout << endl << "Modal result: " << x << endl;
            cout << endl <<  "Press any key to continue...";
            delete Form1;

    Open in new window


    Author Closing Comment

    Thank you for advice.
    You let me know unknown things.
    I will find out another way to return result of my app without printf().

    Thank you again.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
    Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now