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

Can anyone explain how to store a value returns by a linux command in a fortran local variable...

Madhubalan_R_
Beginner
529 Views
Can anyone explain how to store a value returns by a linux command in a fortran local variable without using IO operations.
0 Kudos
3 Replies
Steven_L_Intel1
Employee
529 Views

The standard Fortran intrinsic EXECUTE_COMMAND_LINE does this.

An example:

integer stat
call EXECUTE_COMMAND_LINE('ls',EXITSTAT=stat)

For Intel Fortran this will require compiler version 15.0.1 or later.

0 Kudos
Madhubalan_R_
Beginner
529 Views
Thanks Mr.Steve.But if I want to store the output of the linux command 'whoami' in a fortran variable,What should I do?
0 Kudos
Steven_L_Intel1
Employee
529 Views

Ah, you want to save the output. There's no way I know of to do this without using I/O. However, for this particular purpose I think that the POSIX subroutine PXFGETLOGIN might do what you want.

PXFGETLOGIN

POSIX Subroutine: Gets the name of the user.

Module

USE IFPOSIX

CALL PXFGETLOGIN (s,ilen,ierror)

s

(Output) Character. The returned user name.

ilen

(Output) INTEGER(4). The length of the string stored in s.

ierror

(Output) INTEGER(4). The error status.

If successful, ierror is set to zero; otherwise, an error code.

0 Kudos
Reply