Link to home
Start Free TrialLog in
Avatar of ysre
ysreFlag for Afghanistan

asked on

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
Avatar of ysre
ysre
Flag of Afghanistan image

ASKER

If you can GET nethack working in a virtual console..

Darn typos :)
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
SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ysre

ASKER

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
Avatar of ysre

ASKER

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 :)
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ysre

ASKER

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
Avatar of ysre

ASKER

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
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...
Avatar of ysre

ASKER

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
What do you mean? The coloring of the output? That's done using e.g. 'SetConsoleTextAttribute()'
Avatar of ysre

ASKER

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
>>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.
Avatar of ysre

ASKER

Hm, too bad I can't simply catch the win32 api calls to the console
Thanks a lot for your followup answers, jkr :)

Ys