Read text from an output console

Read text from an output console

Hi, I'm using CFV 6.5 in Windows 2000 to run an executable, and then read the screen output from that executable. Since FORTRAN only reads characters from the screen input (cursor line), I tried using some Windows SDK routines, like ReadConsoleOutput, or ReadConsoleOutputCharacter, but I can't get them to work.
Using ReadConsoleOutput, I get Error 87 (ERROR_INVALID_PARAMETER), and using ReadConsoleOutputCharacter, I'm getting Error 12 (ERROR_INVALID_ACCESS). I think my problem is with the declaration of the variables, can anyone help me on this?
The example I'm trying to follow declares chiBuffer as a CHAR_INFO structure of size 160 (two lines of 80 characters). How can I do that in FORTRAN?

Here's the code I have so far...

Type(T_CHAR_INFO) chiBuffer
Type(T_COORD) coordBufSize
Type(T_COORD) coordBufCoord
Type(T_SMALL_RECT) srctReadRect
type(T_SECURITY_ATTRIBUTES) lpSecurityAttributes
INTEGER hStdout,hNewScreenBuffer,readLength,i
CHARACTER fullMessage*80
LOGICAL status,fSuccess,fSuccess2

hStdout = GetStdHandle(STD_OUTPUT_HANDLE)
hNewScreenBuffer = CreateConsoleScreenBuffer
srctReadRect.Top = 0
srctReadRect.Left = 0
srctReadRect.Bottom = 1
srctReadRect.Right = 79
coordBufSize.Y = 2
coordBufSize.X = 80
coordBufCoord.X = 0
coordBufCoord.Y = 0
fSuccess = ReadConsoleOutput(hStdout,chiBuffer,coordBufSize,
& coordBufCoord,srctReadRect)
tmp=GetLastError ()

c That's where I get Error 87

fsuccess2 = ReadConsoleOutputCharacter(hStdout,fullMessage,
& readLength,coordBufCoord,i)
tmp=GetLastError ()

c That's where I get Error 12



4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Your "chiBuffer" for ReadConsoleOutput should be a two dimensional array to accept the data for each character cell. You probably have to redefined the interface for ReadConsoleOutput, I don't know what is provided with 6.5 though.


There's more than that; the entire concept is wrong:

hStdout = GetStdHandle(STD_OUTPUT_HANDLE)
fSuccess = ReadConsoleOutput(hStdout, chiBuffer,coordBufSize,
& coordBufCoord,srctReadRect)

ReadConsoleOutput does not accept hStdOut handle (which is basically a file/pipe handle), but handle to screen buffer.

See this MSDN article. You can use READ(*,*) and WRITE(*,*) in the child process instead of ReadFile/WriteFile in the sample.


Actually, there is nothing wrong with using the standard output handle in this fashion. Now, is there likely a better way, probably, but we don't know what the problem is that needs to be solved.


Leave a Comment

Please sign in to add a comment. Not a member? Join today