saving output from call system('ls')

Hi,
I like to save output from a system command, and am unable to figure it out. My problem is: The directory '/temp/ has several files, and file name is a combination of English letters and numericals, for example, abc.123.05, zxy.456.05. The file name always has a fixed length. I tried the following, i.e., declared a character vector of size 100, and length of each element is a string of 10 letters, i.e., number of characters in a file name is 10. Looks like I am missing some thing. any help is greatly appreciated.
Thanks
Satish

part of my code is:

character lfnames(100)10,command100

command=‘ls /temp/’

lfnames = call system(command)

END

Hi satishr,

While I have not done this before, I do have one idea. “system” is a lib3f wrapper function for the C system call. It executes the command and returns the exit status code as an integer. My thought is to redirect the command output to a file and then open the file to store in the ifiles variable. Something like:

% cat test.f90
program testb
character*10 ifiles(100)
integer istat,i

istat = system('ls /tmp > /tmp/lslog')
print *, istat
open(100,file='/tmp/lslog')
read(100,'(A10)'), (ifiles(i), i=1,100)
close(100)
print*,ifiles(10)
end program testb
% pgf90 test.f90; a.out
            0
 gcg.dip.o.

Of course, adjust to match your needs.

Hope this helps,
Mat

Hi Mat,
Thanks for the reply. I adjusted character variables as per names of files and length of file names. The program listed all file names but did not create a file.

integer i,istat
character temp*100,lfnames(8213)27,path2100
path2=“prate_9month_forecasthorizon”
temp=“ls “//path2//” >del”
C call system(temp)
istat = system(temp)
print *, istat
END

$pgf90 testsys.f
$a.out
file names … (prate.1988122206.conus.time, prate.2002122706.conus.time)
-2147483648 (this number may corresponds to istat)

Also, it look like I can not use both lines 5 an 6 in a single program, i.e., "call system(temp) " and “istat = system(temp)”. The following error shown up.

$ pgf90 testsys.f
PGF90-S-0084-Illegal use of symbol system - attempt to use a SUBROUTINE as a FUNCTION (testsys.f: 14)
0 inform, 0 warnings, 1 severes, 0 fatal for MAIN

Look forward for your reply.