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

How to run a *nix shell command in a Fortran program?

woshiwuxin
Novice
1,358 Views

Hi, everyone. I want to run a bash command within a Fortran program. I notice there are two functions named "system" and "systemqq" to do this. However, the IFPORT module is required. Is there any intrinsic functions or subroutines to do this without using the IFPORT module?

Thanks in advance!

0 Kudos
1 Solution
Izaak_Beekman
New Contributor II
1,358 Views
There are no system call functions specified by any of the Fortran standards that I am aware of. System calls are always provided by compiler extensions, making them somewhat non-portable. So the answer to your question is no, there are no intrinsic functions or subroutines to do this. You can follow the Intel Compiler documentation to make a system call, or perhaps, you could write it in C and then call it from your Fortran program, which could end up being more portable. (Disclaimer: My experience with c is very limited.)
Good Luck,
Z

View solution in original post

0 Kudos
5 Replies
Izaak_Beekman
New Contributor II
1,359 Views
There are no system call functions specified by any of the Fortran standards that I am aware of. System calls are always provided by compiler extensions, making them somewhat non-portable. So the answer to your question is no, there are no intrinsic functions or subroutines to do this. You can follow the Intel Compiler documentation to make a system call, or perhaps, you could write it in C and then call it from your Fortran program, which could end up being more portable. (Disclaimer: My experience with c is very limited.)
Good Luck,
Z
0 Kudos
woshiwuxin
Novice
1,358 Views

Thanks Z!

I think I will use the functions "system" or "systemqq" in ifport module.

0 Kudos
Steven_L_Intel1
Employee
1,358 Views
I will note that Fortran 2008 specifies an EXECUTE_COMMAND_LINE intrinsic, so this will eventually be coming to a Fortran compiler near you. I can't predict what "eventually" means as far as Intel Fortran goes.
0 Kudos
woshiwuxin
Novice
1,358 Views
It's glad to know this. Nevertheless, "system" and "systemqq" in IFPORT module work well for my simple case.
0 Kudos
John4
Valued Contributor I
1,358 Views

SYSTEM and SYSTEMQQ are executed in an isolated shell (not in the one under which your program runs). If you need/want to execute a command in the same environment, RUNQQ is a better option.

0 Kudos
Reply