Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Send the output to a console from another application????

29 views
Skip to first unread message

Bob Rock

unread,
Dec 31, 2001, 12:16:30 PM12/31/01
to
Hello,

I'd like to have my program (a GUI application) create a console and just
send it a certain output to be displayed.
I don't want to have to code an application that (started by my GUI
application) creates a console, receives the output and prints it but I'd
like to use a standard console application (cmd.exe under winnt/2000 or
command.exe under win9x) and just have it display the output.

Can this be accomplished and how?
Thx.


Regards,
Bob Rock

Igor Tandetnik

unread,
Dec 31, 2001, 12:47:03 PM12/31/01
to
See KB Article Q105305 "INFO: Calling CRT Output Routines from a GUI
Application".
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken

"Bob Rock" <nospam.yet_ano...@hotmail.com> wrote in message
news:a0q6nr$ml01i$1...@ID-98646.news.dfncis.de...

Jason W

unread,
Dec 31, 2001, 8:25:02 PM12/31/01
to
"Bob Rock" <nospam.yet_ano...@hotmail.com> wrote in message
news:a0q6nr$ml01i$1...@ID-98646.news.dfncis.de...

You might be better off having a console app that creates windows rather
than a GUI app that has to AllocConsole(). I've never played with
AllocConsole(). Maybe you will get the same thing either way. All I know is
if you have a console app that happens to create windows, it will all work
fine. But if you may not always want to have the console window, you will
want to go the AllocConsole() route.


Jem Berkes

unread,
Dec 31, 2001, 8:27:39 PM12/31/01
to
> I'd like to have my program (a GUI application) create a console and just
> send it a certain output to be displayed.
> I don't want to have to code an application that (started by my GUI
> application) creates a console, receives the output and prints it but I'd
> like to use a standard console application (cmd.exe under winnt/2000 or
> command.exe under win9x) and just have it display the output.

Look into:

stdio.h
_pipe
popen

Old UNIX tricks. Boy, UNIX has all the answers :)

--
http://www.pc-tools.net/
Windows, Linux & UNIX software

Alex Blekhman

unread,
Jan 1, 2002, 3:03:58 AM1/1/02
to
"Bob Rock" <nospam.yet_ano...@hotmail.com> wrote in
message news:a0q6nr$ml01i$1...@ID-98646.news.dfncis.de...

Q105305 - "INFO: Calling CRT Output Routines from a GUI Application"


Bob Rock

unread,
Jan 1, 2002, 10:33:14 AM1/1/02
to
To clarify my previous post, I'll tell you what I want to do: create a log
function that based on a parameter logs things to a file, to a console or
both. Showing things in a running console can, I suppose, be useful when
monitoring realtime what is happening in your apps.

Regards,
Bob Rock

"Margaret" <marg...@example.com> wrote in message
news:27p13ukfb23ul3e6h...@4ax.com...
> "Bob Rock" <nospam.yet_ano...@hotmail.com>

> hmmm...I mightn't understand your question correctly.
> What happens if you simply include conio.h and call,
> e.g., printf()?
>
> Margaret


Tim Robinson

unread,
Dec 31, 2001, 1:54:10 PM12/31/01
to
Bob Rock <nospam.yet_ano...@hotmail.com> wrote in message
news:a0q6nr$ml01i$1...@ID-98646.news.dfncis.de...
> I'd like to have my program (a GUI application) create a console and just
> send it a certain output to be displayed.

Is AllocConsole() of any use?

That way, AllocConsole() returns a file handle, and you can write to that
handle to print, or read from it to get input.


William DePalo [MVP]

unread,
Jan 1, 2002, 11:43:43 AM1/1/02
to
"Bob Rock" <nospam.yet_ano...@hotmail.com> wrote in message
news:a0sl2d$mqmo2$1...@ID-98646.news.dfncis.de...

> To clarify my previous post, I'll tell you what I want to do: create a log
> function that based on a parameter logs things to a file, to a console or
> both. Showing things in a running console can, I suppose, be useful when
> monitoring realtime what is happening in your apps.

Sometimes when debugging Windows programs I find it convenient to send debug
statements to a console.

The hack below defines the two functions I use to accomplish that -
getConsole() and closeConsole(). The former allocates a console and wires it
to the standard output device. The latter frees it. The console is not
reference counted - multiple get operations return the same console, a
single close deletes it.

Note that it makes printf() work by using the technique described in the kb
article to which Igor directed you. I'm not sure whether that operation is
sufficient to insure that cout would work as well. So in C++ modules I do
something like this:

ostream_withassign cout = getConsole();

cout << "Hello, world";

That seems to work for me.

Regards,
Will

#include <afx.h>
#include <io.h>
#include <stdio.h>
#include <fstream.h>

filebuf *pfb = 0;
ostream_withassign console = 0;

ostream_withassign getConsole()
{
int fd;
FILE *fp;
HANDLE hCon;

if ( console == 0 )
{
// Allocate a console

AllocConsole();

// Make printf happy

hCon = GetStdHandle(STD_OUTPUT_HANDLE);

fd = _open_osfhandle(reinterpret_cast<long>(hCon), 0);
fp = _fdopen(fd, "w");

*stdout = *fp;
setvbuf(stdout, NULL, _IONBF, 0);

// Make cout happy

pfb = new filebuf(fd);
console = pfb;
}

return console;
}

void closeConsole(ostream_withassign ostr)
{
delete pfb;
console = 0;
FreeConsole();
}

Christian Ødum Jensen

unread,
Jan 4, 2002, 4:07:02 AM1/4/02
to
I believe that you may find the solution to you problem
if you let yourself get inspired by the code of the following
library.

ftp://ftp.flipcode.com/cotd/zxlog.zip

regards
Chr. Jensen


"Bob Rock" <nospam.yet_ano...@hotmail.com> wrote in message
news:a0sl2d$mqmo2$1...@ID-98646.news.dfncis.de...

0 new messages