我需要从 Fortran
代码中删除一个文件。我在 ubuntu 12.04, x86_64
上。我不明白为什么下面描述的过程不起作用。请帮我澄清一下情况(实际上,在某些系统上,它可以工作,但在我的系统上不行)。
还有一种方法:我可以直接调用unix命令rm -f file
,但我想知道我的方法有什么问题。谢谢。
第一步,制作简单脚本del.sh,放入~/bin
$ cat del.sh
[ $# -ge 1 ] && rm -f $1
$ chmod u+x del.sh; mv del.sh ~/bin
步骤 2. Fortran 代码,del.for:
character*100 cmd
character*30 file
call getarg(1,file)
write(cmd,100) file
100 format('source del.sh ',a30)
call system(cmd)
end
第三步编译运行:
$ ifort -o del del.for
$ ./del file
结果:
sh: 1: source: not found
怎么了?简单的“源 del.sh 文件”有效,但不适用于 Fortran 代码……这令人困惑。
来自 Fortran 代码:
100 format('del.sh ',a30)
100 format('bash del.sh ',a30)
工作完美,但是
100 format('sh del.sh ',a30)
不起作用。我安装了 bash
,但没有安装 csh
。谢谢。
最佳答案
为什么不让 Fortran 为您代劳呢?此代码是可移植的(比较cup的注释):
open(unit=1234, iostat=stat, file=file, status='old')
if (stat == 0) close(1234, status='delete')
关于linux - 如何从 Fortran 代码中删除文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18668832/