- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
"./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 .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is there a program "exmple_folder" in the directory where you execute the Fortran program above?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear J.,
Really Really thanks.
Now it works
Really Really thanks again
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page