Hello,
I have tested the following code (ftn95 v9.06), which works using system but fails with execute_command_line:
program dos_cmd
integer :: i
character(len=512) :: cmd
!Input string using programs grdinfo, piping and gawk (programs in PATH)
!Get header info from a netCDF file using GMT
cmd = 'grdinfo Bathy_crop1_scaled.grd -C | ' // &
'gawk '{xmin=$2; xmax=$3; ymin=$4; ymax=$5; nx=$10; ny=$11};' // &
'{print xmin, xmax, ymin, ymax, 2*nx, 2*ny}' > nxy.txt'
print *, 'Executing command:'
print *, trim(cmd)
!test alternate command-line calls
call system(cmd) ! works
call execute_command_line(cmd, exitstat=i) ! fails (F2008 intrinsic)
print *, 'Exit status of external_prog.exe was ', i
end program dos_cmd
system(cmd) correctly writes nxy.txt. However execute_command_line(cmd,exitstat=i) fails with run-time error:
Executing command:
grdinfo Bathy_crop1_scaled.grd -C | gawk '{xmin=$2; xmax=$3; ymin=$4; ymax=$5; nx=$10; ny=$11};{print xmin, xmax, ymin,
ymax, 2*nx, 2*ny}' > nxy.txt
grdinfo [ERROR]: Cannot find file |
grdinfo [ERROR]: Cannot find file gawk
grdinfo [ERROR]: Cannot find file {xmin
Exit status of external_prog.exe was 72
Any ideas why the second call fails? grdinfo, gawk all sit in the windows PATH.
Not a big issue, just curious to know why there is a difference in behaviour.
Lester