mingw32-gcc: How to create a real terminal (for the win32 console application) that does not differ from the real deal (cmd.exe) ?

Hi,

the problem I got is the following:
nethack (a very nice text rpg for those who don't know) has a win32 console version.
The binary itself works nicely from the console (either starting a new console process or executing cmd.exe, then nethack.exe).
But whenever I'm trying to redirect all the 3 outputs (stdin, stdout, stderr) from my newly created process  I don't either get anything at all (on the shown console window and my pipes).. or I only get output/input on the shown console window (but none over my pipes).

It seems nethack detects that my virtual console isn't the real deal and simply strains to run (or more probable: It doesn't [couldn't find anything in the source on the restraining], but the output gets sent somewhere completely else or discarded completely).

Any ideas on how to solve this issue?
Some source code would be nice if you can nethack working :)

Ys
LVL 4
ysreAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ysreAuthor Commented:
If you can GET nethack working in a virtual console..

Darn typos :)
PaulCaswellCommented:
Hi ysre,

Its probably not using stdin/stdout/stderr. A DOS tool can, and often does use BIOS functionality for the speed advantage. It is also possible to write directly to screen memory (which would also be emulated) so I suspect you're flogging a dead horse here I'm afraid.

Paul
jkrCommented:
How are you doing thast right now? Like in http://support.microsoft.com/kb/190351/en-us ("How to spawn console processes with redirected standard handles") or in a different way?
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

ysreAuthor Commented:
jkr: I tried it the way described in the MSKB entry and tried some other things (eg. libexecstream). To no avail of course ;)
Paul: Yeah, that's what I figured, only nethack doesn't have any BIOS calls in its win32 tty implementation (WriteConsoleOutputCharacter and WriteConsoleOutputAttribute).

Or are these bios calls?

Ys
ysreAuthor Commented:
Oh and one more thing:
If the original cmd.exe can intercept BIOS calls (it prolly should be able to do this)  how can my measly little wrapper do the same?
There must be an easy way to do this :)
PaulCaswellCommented:
>>There must be an easy way to do this...
'fraid not. Take a look at what you'd have to emulate just to catch bios calls:

http://heim.ifi.uio.no/~stanisls/helppc/int_10.html

Then you'd still have to catch memory access to b800:0000 onwards for programs that write directly to the screen.

I suppose you may be able to find a way of scraping the screen with a TSR but even that would be exceptionally complex. Not something you could knock up in a few days certainly.

Paul

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ysreAuthor Commented:
Hm at this point I have no real answer on what I should ask.. and the question isn't really answered to my content.
But at the same time I just can't go on asking more and more, since this will be a looong post if we keep on doing that :)

So at this point I'll split the point, hoping I can come up with some more decent..

Besides, the WriteConsole* functions (used by nethack) are BIOS calls or normal windows console calls?

Ys
ysreAuthor Commented:
I guess closing a question with points distribution appreciating the replies so far isn't the best way to get some short answers
Who'd have thought hehe :)

I'll take a note and not distribute from now on :)

Ys
jkrCommented:
Probably because it does not make sense to mix cmd.exe with BIOS calls - they are two different things that do not have anything in common. You cannot use privileged code that would call the BIOS in Win32 user mode anyway...
ysreAuthor Commented:
Hm yeah, that makes sense.
But still the cmd.exe that comes with Windows (NT in any form) reliably outputs stuff the way it's supposed to do when it comes to the win32 nethack binary :)
So it surely has some workaround implemented for this.. Now only if I could get my hands on the source hehe

Ys
jkrCommented:
What do you mean? The coloring of the output? That's done using e.g. 'SetConsoleTextAttribute()'
ysreAuthor Commented:
Hm nethack uses this SCTA function.. and WriteConsoleOutputCharacter (..) as well as FillConsoleOutputAttribute (..).
So are these BIOS calls or just standard Windows console calls?

In case these are standard Windows console calls, shouldn't they be catchable using standard redirects?

If you want, see sys/winnt/nttty.c in nethack's source (available at www.nethack.org) ;)

Ys
jkrCommented:
>>So are these BIOS calls or just standard Windows console calls?

These are standard Win32 API calls.

>>In case these are standard Windows console calls, shouldn't they be catchable using standard redirects?

No, since they don't have anything to do with redirects. Only 'ReadConsoleOutputAttribute()' and friends will help you here.
ysreAuthor Commented:
Hm, too bad I can't simply catch the win32 api calls to the console
Thanks a lot for your followup answers, jkr :)

Ys

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.