Capturing and hiding console output!

Posted on 2004-04-30
Medium Priority
Last Modified: 2007-12-19
Hello experts,

Im using this code to execute a console aplication from a Borland Builder Form :

      ZeroMemory( &si, sizeof(si) );
      si.cb = sizeof(si);
      ZeroMemory( &pi, sizeof(pi) );

      // Start the child process.
      if( !CreateProcess( file, // No module name (use command line).
                  params, // Command line.
                  NULL,             // Process handle not inheritable.
                  NULL,             // Thread handle not inheritable.
                  FALSE,            // Set handle inheritance to FALSE.
                  0,                // No creation flags.
                  NULL,             // Use parent's environment block.
                  dir,             // Use parent's starting directory.
                  &si,              // Pointer to STARTUPINFO structure.
                  &pi )             // Pointer to PROCESS_INFORMATION structure.

I use this method, because I want to wait until the console application finishes to launch another application using :

      // Wait until child process exits.
      while (WaitForSingleObject( pi.hProcess, 50 )==WAIT_TIMEOUT)

So the execution is handled, now to the interesting part.
using THIS CODE or one that has the SAME BEHAVIOUR...

is there a way to capture the output from this console application?
is there a way to COMPLETELY hide the console application from the user?

ovbiously I'm using windoze!

Question by:javock
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
LVL 17

Expert Comment

ID: 10964335

to hide
si.wShowWindow = SW_HIDE;

to capture You must create pipes
wait a moment
LVL 17

Assisted Solution

mokule earned 1200 total points
ID: 10964366

Author Comment

ID: 10964430
I'll have to checkout about the pipes...

On a rapid test, SW_HIDE didn't work...

Will see tomorrow with more time!

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 17

Assisted Solution

mokule earned 1200 total points
ID: 10964587

     si.cb = sizeof(si);
     si.wShowWindow = SW_HIDE;

LVL 48

Expert Comment

ID: 10966386
To hide console wndow use CREATE_NO_WINDOW flag in the dwCreationFlags CreateProcess parameters.

To redirect console input/output use lpStartupInfo CreateProcess parameter. STARTUPINFO::dwFlags should include STARTF_USESTDHANDLES flags, and STARTUPINFO members hStdInput, hStdOutput and hStdError should be pipe or file handles for input/output. Unfortunately, it's impossible to regirect onlt process output. You must redirect all handles.
You can use pipes or files. Using of files is less flexible but simple. For example, if you know that process doesn't use any input, open emplty file using CreateFile function with read permissions, and pass it's handle as hStdInput. Create two new files using CreateFile function with write permissions, and pass these handles as hStdOutput and hStdError. After process finished, read hStdOutput file - this is process output.

Author Comment

ID: 10967130

The console application does not expect input, so it would be read only. But, the process is quite long, and I would like to read output as it comes (during execution) and not when the application has finished...


Author Comment

ID: 10967175
Now that I think, that is not possible right? read output as it comes out... and react to it... I have this progressbar and the console aplication prints a dot for each percent of process done, so I would like to read this output and increment the bar as each new dot appears...

also it could be useful to show the output as a debug tool, and to hide it for the user when the application has ended.

LVL 48

Accepted Solution

AlexFM earned 800 total points
ID: 10968184
In this case use pipes. Pipe is created using CreatePipe, and ReadFile is used to read process output.


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
Suggested Courses

762 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