Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28385 Discussions

runtime error when using system() function

Steve_M_3
Beginner
325 Views

Hi

I have a working program, written in fortran, using Visual Studio 2010 and Intel Visual Fortran 2011.13.371.  A simple console application.

I'm trying to execute a system call from within my fortran program.  I added a subroutine to my program, with this code:

SUBROUTINE MINE

USE IFPORT

INTEGER I4STAT

CHARACTER*100 DOT

DOT = "DIR"

I4STAT = SYSTEM(DOT)

RETURN

END

I call subroutine MINE from my main program, it bombs every time.

I've built it in debug and release mode, linking with every choice for "Runtime Library" that is available.  Every time, I get an unhandled exception error: Access violation reading location xxxxxx when the call to SYSTEM is executed.  ???

 

Help Please

0 Kudos
5 Replies
JVanB
Valued Contributor II
325 Views

Works fine and prints out the directory with 16.0.2.180. Are you building a Windows application or a console application?

 

0 Kudos
Steven_L_Intel1
Employee
325 Views

Seems to work fine in the older version too:

C:\Projects\U620342>type U620342.f90
SUBROUTINE MINE
USE IFPORT
INTEGER I4STAT
CHARACTER*100 DOT

DOT = "DIR"
I4STAT = SYSTEM(DOT)
RETURN
END

PROGRAM U620342
CALL MINE
END
C:\Projects\U620342>ifort /logo U620342.f90
Intel(R) Visual Fortran Compiler XE for applications running on IA-32, Versio
2.0.5.221 Build 20110719
Copyright (C) 1985-2011 Intel Corporation.  All rights reserved.

Microsoft (R) Incremental Linker Version 9.00.30729.01
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:U620342.exe
-subsystem:console
U620342.obj

C:\Projects\U620342>U620342.exe
 Volume in drive C is OSDisk
 Volume Serial Number is 6E33-836D

 Directory of C:\Projects\U620342

03/17/2016  01:11 PM    <DIR>          .
03/17/2016  01:11 PM    <DIR>          ..
03/17/2016  01:11 PM           284,672 U620342.exe
03/17/2016  01:10 PM               147 U620342.f90
03/17/2016  01:11 PM             1,078 U620342.obj
               3 File(s)        285,897 bytes
               2 Dir(s)  655,367,397,376 bytes free

C:\Projects\U620342>

Please show us what you are doing that is different. (The version you show is the Visual Studio integration, not the compiler version.)

0 Kudos
Steve_M_3
Beginner
325 Views

Thanks for quick reply.  I'll try to be more clear this time...

I started fresh.  Launched Visual Studio, selected "New Project", Intel Visual Fortran Console Application, Main Program Code, and named it "Console2".  I added a few lines to Console2.f90, I'm getting the same error.  Here is the Console2.f90 code:

!  Console2.f90 
!
!  FUNCTIONS:
!  Console2 - Entry point of console application.
!

!****************************************************************************
!
!  PROGRAM: Console2
!
!  PURPOSE:  Entry point for the console application.
!
!****************************************************************************

    program Console2

    USE IFPORT
    implicit none
    integer i4stat
    character*100 dot

    ! Variables

    ! Body of Console2
    print *, 'Hello World'

    dot="dir"
    i4stat = system(dot)
    write(*,*)'back'
    read(*,*)
    
    end program Console2

When I debug line by line, it blows up on the call to System().  In the command window, it shows Console2.exe calls libifportMD.dll, then kernel32.dll twice, then privman32.dll twice, then ntdll.dll.  Says forrtl: severe (157): Program Exception - access violation.

I know this works, I've done it before.  I've tried building with various runtime libraries, debug/release modes, etc.  I've looked thru the help, the forums, and I'm stuck.

Thanks for you attention.

0 Kudos
Steve_M_3
Beginner
325 Views

Hold a sec, I need to ask the question differently...

I've been running the program through visual studio, and getting the error.  I just now opened up a dos box and ran the Console2.exe program, it works fine.  Both the debug and release versions work fine, as long as I run from the dos box.  I get the error every time when running through the debugger.  So I can't run in the debugger if I make a call to System()?

0 Kudos
Steven_L_Intel1
Employee
325 Views

I just tried what you described and it worked ok, using VS2010 and the 12.0.5 compiler.

I notice you mention a "privman32.dll" in the call chain. This is a part of a product called BeyondTrust Privilege Manager - it's not part of Intel Fortran and not part of Windows. An interesting experiment would be to change the Fortran > Libraries > Use Runtime Library property to "Multithreaded" instead of "Debug Multithreaded DLL", rebuild, and see if the error is still there.

It could be that this BeyondTrust DLL that has inserted itself into Windows is responsible for the problem.

0 Kudos
Reply