?
Solved

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

Posted on 2006-04-07
14
Medium Priority
?
359 Views
Last Modified: 2008-02-26
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
0
Comment
Question by:ysre
  • 8
  • 4
  • 2
14 Comments
 
LVL 4

Author Comment

by:ysre
ID: 16405118
If you can GET nethack working in a virtual console..

Darn typos :)
0
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 16405570
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
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 375 total points
ID: 16405914
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?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 4

Author Comment

by:ysre
ID: 16406041
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
0
 
LVL 4

Author Comment

by:ysre
ID: 16406712
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 :)
0
 
LVL 16

Accepted Solution

by:
PaulCaswell earned 1125 total points
ID: 16406752
>>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
0
 
LVL 4

Author Comment

by:ysre
ID: 16409795
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
0
 
LVL 4

Author Comment

by:ysre
ID: 16428957
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
0
 
LVL 86

Expert Comment

by:jkr
ID: 16429273
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...
0
 
LVL 4

Author Comment

by:ysre
ID: 16429895
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
0
 
LVL 86

Expert Comment

by:jkr
ID: 16430026
What do you mean? The coloring of the output? That's done using e.g. 'SetConsoleTextAttribute()'
0
 
LVL 4

Author Comment

by:ysre
ID: 16430352
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
0
 
LVL 86

Expert Comment

by:jkr
ID: 16430923
>>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.
0
 
LVL 4

Author Comment

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

Ys

0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question