This is the mail archive of the cygwin-xfree@cygwin.com mailing list for the Cygwin XFree86 project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

console IO in GUI apps


Christopher Fayler wrote:
 >FWIW, this is exact problem plagues the
 >Windows version of insight (aka gdb). The
 >only solution we ever came up with was either
 >to call AllocConsole when we needed to
 >write something to a console -- which sucks
 >for when you're starting the program via the
 >console, or to build the program as a console
 >app -- which means that you always get a
 >flashing black box if you double click on a gdb icon.
 >
 >It *looks* like the MSVC program somehow
 >manages to do what we want here since it seems
 >to exist as both a console and a windows app
 >but I was never able to figure out how to do
 >what it did. Most likely, I am just misinterpreting
 >what it does do.


Chris, if I understand you correctly, then you want
the (GUI) application to detect whether or not it
was launched from an existing shell and then to use
the shell it was run from for its console.  Otherwise,
you want to spawn a new console.  IIRC, when an
application is launched from a console, then you can
just use standard in and standard out and it works as
if by magic.  I presume xterms and whatnot will work
similarly.  So to achieve what you want, I think you
just have to figure out whether or not STDOUT is
"hooked up" to anything, and if not, AllocConsole.
If there's no easy way to do that, then you could use
a command line parameter which the user includes in
his or her shortcuts but doesn't use from the commandline.
If you print to STDOUT and it's not there, nothing bad
happens so you don't have to worry too much.

I would also mention that there is an AttachConsole
where you can use an already existing console, you just
have to know the console owner's PID.  But xterms etc
won't be windows consoles (I presume), so it's probably
not that useful.

One last thing I tripped over, if things don't "just work":

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/prothred_4uus.asp

This shows how you can reroute a child process's
standard in and out to pipes, which you can then do
whatever you want with.  Not saying you want to do
this, but it might give you some other ideas.

Augustus



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]