可以使用库例程 getarg(3F) 在运行时将命令行参数读入字符变量。参数会被解释为文件名并在 OPEN 语句的 FILE= 说明符中使用:
demo% cat testarg.f CHARACTER outfile*40 C Get first arg as output file name for unit 51 CALL getarg(1,outfile) OPEN(51,FILE=outfile) WRITE(51,*) ’Writing to file: ’, outfile END demo% f95 -o tstarg testarg.f demo% tstarg AnyFileName demo% cat AnyFileName Writing to file: AnyFileName demo% |