Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I output to console?

Status
Not open for further replies.

c567591

MIS
Aug 12, 2002
67
US
How do I output text to the same console that started the process?

If I use:
void writeln(String text)
{
// fprintf(stderr, "%s\n", text.c_str());
static HANDLE handle;
if (!handle) {
AllocConsole();
handle = GetStdHandle(STD_OUTPUT_HANDLE);
}
text += "\n";
WriteConsole(handle, text.c_str(), text.Length(), 0, 0);
}

It creates a new console window.
I want my output to go to the same console window that started it.
This is a full BCB GUI app using the VCL if it matters.
I have dug through all the C & Delphi stuff I can find but haven't found the answer yet.

Thanks!
 
I'm not sure why you want to write to the console if this is a GUI app. I drop a TMemo on the screen and write to that. Much easier, IMHO.



James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
I want to output the command line parameters & its help to the console that opened it.
That way they can see the commands and correct them as needed.

Normally, yes a TMemo is a great way, but for this, it is not what I am after.
There are a lot of command line parameters and it is very helpful to have them all on the screen so that they can all get entered correctly. I have seen other programs do this, so I know its possible.
 
What happens, then, when you run, " fprintf(stderr, "%s\n", text.c_str());"?



James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
I see it in a new window that flashes up and immediately closes. stdout/stderr both do same thing.

Somehow I need the stdout/stderr of the parent process I guess.
 
As an experiment, try putting in a bit of code that asks for input after the fprintf. For example, in using stdout, I would use:
char Y;
cin >> Y;

or something similar.

James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
Even if that does work (will try in a bit), it is still not in the original command window.
 
No, that's still doing a new window.
Any idea how to get the handle of the parent process?
 
Let me look around. I THINK I may have read something about that.


James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
I started with that Writeln atricle, thats how this process began.
I haven't seen that other article, so I will give that a shot.
I appreciate you sticking this out to help me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top