Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Read text from an output console

jpmatsuura
Beginner
1,404 Views
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...

USE DFWIN
USE KERNEL32
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
& (GENERIC_WRITE,0,lpSecurityAttributes,CONSOLE_TEXTMODE_BUFFER,0)
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

readLength=80
fsuccess2 = ReadConsoleOutputCharacter(hStdout,fullMessage,
& readLength,coordBufCoord,i)
write(*,*)chiBuffer.ASCIIChar,i
tmp=GetLastError ()
write(*,*)chiBuffer.ASCIIChar,tmp

c That's where I get Error 12

Thanks,

JP
0 Kudos
3 Replies
james1
Beginner
1,404 Views
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.

James
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,404 Views
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.

Jugoslav
0 Kudos
james1
Beginner
1,404 Views
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.

James
0 Kudos
Reply