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

call system error sh

diedro
Beginner
1,070 Views

Dear all,

I have written this simple program to test "call system":

PROGRAM unixsystem
IMPLICIT NONE

CHARACTER(LEN=30) :: cmd !string to store the Unix command
 cmd = "./pwd" ! As an example print the working directory
CALL SYSTEM(cmd)

END PROGRAM unixsystem

 

However, I get the following error:

sh: 1: ./pwd: not found

I do not understand why. Very similar fortran codes used to work on my laptop.

I am using:

ifort (IFORT) 18.0.2 20180210
Copyright (C) 1985-2018 Intel Corporation.  All rights reserved.

 

Thanks for any help

0 Kudos
10 Replies
Juergen_R_R
Valued Contributor I
1,070 Views

"./pwd" is a local command that the OS environment searches for in the executed directory. If you want to call the system command, use "pwd", not "./pwd". Note that system is an extension and not part of the Fortran standard. The correct command from the Fortran 2008 status is execute_command_line. gfortran flags "call system (cmd)" as an error when setting -std=f2008, in principle ifort should do the same with the -e08 options, but unfortunately it doesn't . 

0 Kudos
diedro
Beginner
1,070 Views

Dear all, Dear Juergen,

The word "pwd" is just and example.

What I want to do is to create a folder from Fortran:

PROGRAM unixsystem
IMPLICIT NONE

CHARACTER(LEN=50) :: cmd !string to store the Unix command
cmd = "./exmple_folder"

END PROGRAM unixsystem

 

What do you think? I have correctly understood your answer?

Thanks

 

0 Kudos
Juergen_R_R
Valued Contributor I
1,070 Views

Is there a program "exmple_folder" in the directory where you execute the Fortran program above?

 

0 Kudos
diedro
Beginner
1,070 Views

Dear J, Dear all,

I would like to create "example_folder" inside the directory where I am executing the program as usually I have already done a lot of time. However, It seems not working any more.

 

what do you think?

D.

0 Kudos
Juergen_R_R
Valued Contributor I
1,070 Views

Cynically I could say: "You didn't answer my question, why should I answer yours?" Ok, if you want to create an folder "example_folder", then do so: 

call execute_command_line ("mkdir example_folder")

 

0 Kudos
diedro
Beginner
1,070 Views

Dear J.,

Really Really thanks.

Now it works

Really Really thanks again

0 Kudos
Navdeep_Rana
Beginner
1,070 Views

Juergen R. wrote:

Cynically I could say: "You didn't answer my question, why should I answer yours?" Ok, if you want to create an folder "example_folder", then do so: 

call execute_command_line ("mkdir example_folder")

 

I would like to add something to Juergen's answer. Add "-p" flag, it's useful if working with subdirectories.

call execute_command_line("mkdir -p dir_name/subdir_name")

will create both.

0 Kudos
Steve_Lionel
Honored Contributor III
1,070 Views

Juergen R. wrote:
 gfortran flags "call system (cmd)" as an error when setting -std=f2008, in principle ifort should do the same with the -e08 options, but unfortunately it doesn't . 

I would say “Fortunately, it doesn’t,” There is nothing nonstandard about the syntax of that call to some external procedure named SYSTEM. Now, if gfortran has made SYSTEM an intrinsic, then I could see a diagnostic being warranted. Intel Fortran does not consider SYSTEM an intrinsic, it’s just another external procedure.

You can get ifort to give errors for standards violations (-warn stderror), but this is not such a case.

0 Kudos
Juergen_R_R
Valued Contributor I
1,070 Views

Steve Lionel (Ret.) wrote:

I would say “Fortunately, it doesn’t,” There is nothing nonstandard about the syntax of that call to some external procedure named SYSTEM. Now, if gfortran has made SYSTEM an intrinsic, then I could see a diagnostic being warranted. Intel Fortran does not consider SYSTEM an intrinsic, it’s just another external procedure.

You can get ifort to give errors for standards violations (-warn stderror), but this is not such a case.

Steve, that is of course true. I am confused by the fact that ifort does support the features of the "system" subroutine, if I compile the original example (replacing "./pwd" with "pwd") then this works with the Intel compiler and gives the current directory. So ifort does support a "system" intrinsic. Otherwise I would have expected a "symbol _system not found" error message from the runtime library.

 

0 Kudos
Steve_Lionel
Honored Contributor III
1,070 Views

No, ifort supports a SYSTEM “portability routine”. Its default interface is what one expects for SYSTEM. You can USE IFPORT if you want, but most of the portability routines don’t require it.

Ifort does have some former portability routines that got turned into intrinsics -  malloc and free are two.

An intrinsic is one that is recognized internally by the compiler. SYSTEM is not.

 

0 Kudos
Reply