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

Nobuo Miwa
Nobuo Miwa used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2013

Commented:
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

or
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:
notepad.exe

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)
jkr
Top Expert 2012

Commented:
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()' (http://msdn.microsoft.com/en-us/library/windows/desktop/aa363362(v=vs.85).aspx) and watch the output e.g. using "DebugView" (http://msdn.microsoft.com/en-us/vstudio/bb896647)

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

Author

Commented:
Thanks quick advice,

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

Regards,
Nobuo Miwa
Expert Spotlight: Joe Anderson (DatabaseMX)

We’ve posted a new Expert Spotlight!  Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.

jkr
Top Expert 2012
Commented:
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()' (http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx)
Top Expert 2013
Commented:
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);
        BringWindowToTop(hWnd);

        // Display the results of the modal form.
        cout << endl << "Modal result: " << x << endl;
        cout << endl <<  "Press any key to continue...";
        getch();
        delete Form1;

Open in new window

Nobuo MiwaSecurity Engineer

Author

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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial