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

system interaction, fortran 2003 standard (getting stdout revisited)

rreis
New Contributor I
586 Views
related to previous questions of capturing STDOUT from a system command I went through the 2003 standard. It has this intrinsic features:

---
3 13.5.18 System environment procedures
4 COMMAND ARGUMENT COUNT () Number of command arguments
5 CPU TIME (TIME) Obtain processor time
DATE AND TIME ([DATE, TIME, ZONE, Obtain date and time
6 VALUES])
GET COMMAND ([COMMAND, Returns entire command
7 LENGTH, STATUS])
GET COMMAND ARGUMENT (NUMBER Returns a command argument
8 [, VALUE, LENGTH, STATUS])
GET ENVIRONMENT VARIABLE (NAME Obtain the value of an environment variable
[, VALUE, LENGTH, STATUS,
9 TRIM NAME])
10 IS IOSTAT END (I) Test for end-of-le value
11 IS IOSTAT EOR (I) Test for end-of-record value
SYSTEM CLOCK ([COUNT, Obtain data from the system clock
12 COUNT RATE, COUNT MAX])
----

My curiosity was about what does "GET COMMAND", "GET COMMAND ARGUMENT" really do. So, just for correctness, "COMMAND ARGUMENT" allows me to get stuff like

$ ./a.out arg1 arg2 arg3

arg1, arg2, arg3 inside my program

and I can "capture" some of the stdout (simple stuff) with

call system("export UNAVAR=`uname`")
GET_ENVIRONMENT_VARIABLE ("UNAVAR", uname_var)

? can someone just confirm this?

best!
0 Kudos
4 Replies
rreis
New Contributor I
586 Views
I've realized this can have portability issues because of the different shells where it can run...

(maybe invoque GET_ENVIRONMENT_VARIABLE to retrive $SHELL value first and act accordingly?)
0 Kudos
Steven_L_Intel1
Employee
586 Views
GET_COMMAND_ARGUMENT is like the C "getarg", GET_ENVIRONMENT_VARIABLE is like C "getenv". Calling SYSTEM to set an environment variable may not do anything for you, as that typically happens in another process context. There is not yet a corresponding SET_ENVIRONMENT_VARIABLE, though it might be in F2008 (I am away from my copy of that to see.) You can certainly use GET_ENVIRONMENT_VARIABLE to query any environment variables visible to you.
0 Kudos
rreis
New Contributor I
586 Views
GET_COMMAND_ARGUMENT is like the C "getarg", GET_ENVIRONMENT_VARIABLE is like C "getenv". Calling SYSTEM to set an environment variable may not do anything for you, as that typically happens in another process context. There is not yet a corresponding SET_ENVIRONMENT_VARIABLE, though it might be in F2008 (I am away from my copy of that to see.) You can certainly use GET_ENVIRONMENT_VARIABLE to query any environment variables visible to you.

I did not remember that the process spawned by CALL SYSTEM could (would?) be in another context. Thanks for point it out.

If there's a F2008 draft... anyway to slide some usefull way to capture stdout? After all that's the "holy grail", if I can use such expression... or such need was never felt/expressed by the people deciding the language? Just curious.
0 Kudos
Steven_L_Intel1
Employee
586 Views
Fortran 2008 defines an EXECUTE_COMMAND_LINE intrinsic, but no provision is made for capturing output.
0 Kudos
Reply