Problem directing Input/Output to Console

Problem directing Input/Output to Console

I am porting an application from Unix to Windows NT. The complete
application consists of one executable built with FORTRAN source code and
Unix shell scripts. I have already built a console application with the
FORTRAN source code and the Unix shell scripts have been converted to Perl

Problem : The original shell scripts is setting some environment variables,
which are looked for by the executable. One of the variables is set
to the value returned by a Unix utility 'tty'. This utility on Unix displays
the terminal name. The problem I am facing is that the Fortran
executable is opening with the filename specified as this terminal name. The
subsequent READ and WRITE statements using the Unit specifier,(
specified with the open statement while opening this terminal) are now
directed to this terminal. Since there is no such utility as 'tty' on
Windows, what I need to work out is same logic in which the open
statement should open a unit directed to CONSOLE. The following subsequent
READ and WRITE statements with the Unit specifier, as specified
in the open statement while opening file directed to
CONSOLE, should now read and write on the CONSOLE.

What I have tried : I have already tried the following.
Given open statements with File name specified as 'CON',
'USER', 'CONOUT$' and 'CONIN$'. While the
subsequent WRITE statements are successful for the first three and the READ
statements are failing, the READ statements are
successful for the last one and WRITE statements fail.

Please let me know how can I work out a solution for this. How can I achieve
the similar functionality for the application when ported to Windows NT.

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

Any reason you couldn't just use standard units 5 and 6?


It's like this. On run time, depending upon the option you choose the fortran application will open the terminal as file with unit specifier as say 13 or some other number. Now using this unit number you will read and write to the terminal with 'READ' and 'WRITE' statements. Doing this on Windows means opening Console as file with some unit number and then using this unit number you have to read and write using 'READ' and 'WRITE' statements. Any solution to this??

If you read from 5 and write to 6, you could just define the appropriate environment variable on each platform to redirect from a terminal to a file if desired.

Anyhow you cannot open CONIN$ or CONOUT$ on one unit and do reads and writes. You would have to read from one unit and write to another. This is because with a Windows console application CONIN$ is the keyboard (readonly) and CONOUT$ is the console screen buffer (writeonly).

Since unit 5 is CONIN$ and unit 6 in CONOUT$ under Windows, that would seem to provide a portable mechanism between your two platforms.

That said though CON should work I believe.


Leave a Comment

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