Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Execute a DOS command from Fortran

30 views
Skip to first unread message

Mike

unread,
Aug 22, 2014, 11:24:10 AM8/22/14
to
Hi Group,

I am having problems building some Fortran source into a DOS executable.

I should explaine the reason for doing this is to check that the source
performs in the same way as the original program.

The source segments looks like this:

I = EXDOS('TYPE FSMENU.TXT')

and the functions looks like this including comments to assist in its
understanding:

INTEGER FUNCTION EXDOS( CMD )

* * Issue a DOS command from within an executing FORTRAN
application.
* * Can be used to implement overlays of pre-compiled "EXE"
programs.

* * Example: Issue a DOS 'COPY' command
* * RETCOD = EXDOS( 'COPY *.FOR \BACKUP\FORTRAN' )

* * Example: Run two separate parts of an appli*ation
* * RETCOD = EXDOS( 'PART1' )
* * RETCOD = EXDOS( 'PART2' )

* * Requirements: This program uses the integer-valued FORK and
DOSENV
* * functions located in WATFOR.LIB.

character*(*) cmd
integer fork, dosenv, com_len
character comspec*80, cmdlin*128
com_len = dosenv( 'COMSPEC', comspec )
if( com_len .eq. 0 )then
comspec = 'command.com'
com_len = 11
endif
comspec(com_len+1:com_len+1) = char(0)
cmdlin(1:1) = char( 3 + len( cmd ) )
cmdlin(2:4) = '/* '
cmdlin(5:) = cmd
exdos = fork( comspec, cmdlin )
end

**Referencing library: FORK - E:\WF77\WATFOR.LIB(FORK)

**Referencing library: DOSENV - E:\WF77\WATFOR.LIB(DOSENV)

**Referencing library: EXT_TO_WF77 - E:\WF77\WATFOR.LIB(WEXT)

As you can see the function call is trying to diplay a text file to screen
and uses a library called WATFOR.LIB.

The build executable when run returns the following error:

16 bit MS_DOS Subsystem
c:\Windows\system32\cmd.exe - fs_opt (which is the name of the program)
The NTVDM CPU has encountered an illegal instruction

Does anyone know if WARFOR.LIB is a WATCOM product?
Is there an alternative solution for issuing DOS commands from Fortran
statements?

Thanks for any assistance.

Regards,

Mike


Robert Miles

unread,
Aug 23, 2014, 1:24:08 AM8/23/14
to
WATFOR is the name of a FORTRAN compiler that I used back when I was
first learning FORTRAN, around 1970. It then ran on an IBM 360
mainframe over in the next county.

As far as I know, Watcom has never reused that name for one of
their products.

The C library includes a function to tell the operating system to
run a command. I don't remember clearly just what function, but
I'd first try looking up the system() function.

It shouldn't take much effort to write a C function to interface
that function to Fortran. However, expect the result to be specific
to one Fortran compiler and one C library. The Fortran standards do
not include a standard way to do what you want.

Lynn McGuire

unread,
Aug 25, 2014, 3:21:06 PM8/25/14
to
On 8/22/2014 10:24 AM, Mike wrote:
Hi Mike,

Open Watcom F77 uses the FSYSTEM command to execute
dos system commands.
http://www.openwatcom.org/ftp/manuals/current/fuguide.pdf

Lynn


dpb

unread,
Nov 1, 2014, 9:05:51 AM11/1/14
to
On 08/23/2014 12:24 AM, Robert Miles wrote:
...

> It shouldn't take much effort to write a C function to interface
> that function to Fortran. However, expect the result to be specific
> to one Fortran compiler and one C library. The Fortran standards do
> not include a standard way to do what you want.

While not helpful for legacy compilers like Watcom F77, for completeness
it should be noted that as F2008 there _is_ Standard-conforming way with
the inclusion of --

call execute_command_line(command[,wait,exitstat,cmdstat,cmdmsg])

starts execution of another program if the processor supports command
line execution.

EXECUTE_COMMAND_LINE is a new included intrinsic subroutine along with
quite a few others for many such common tasks included in F2003 and F2008.

--



0 new messages