I want to create a Python script to run many Fortran files "at once". The main reason for this is that I've done many Fortran numerical simulations, so I want to speed up to get the process of running all of the Fortran Files with one click (in general, the numerical solutions will be altered according to some input archive, thus, it is useful to modify the input and run the python scripts, which will compile and execute the Fortran programs, and by the way, there are other scripts to plot and obtain linear regression). The code is as follows:
# ------ Run the compiler (ucnum8.f) and run the .exe (ucnum8.exe) by a script ---------
# All other modules were imported at the beginning of the code, which I didn't place here
# Import modules
import subprocess, os
# sub_subdir_baixa is a list of directories
for e in sub_subdir_baixa:
print(f'Compiling and running {e}...')
# Change the directory to the specified subdirectory
os.chdir(e)
# Compilation command
compile_command = f'gfortran ucnum8.f -o ucnum8'
subprocess.run(compile_command, shell=True)
# Execute the command
execute_command = './ucnum8.exe'
subprocess.run(execute_command, shell=True)
os.chdir('..')
The Error reads: '.' is not recognized as an internal or external command, operable program or batch file. The Fortran compilation works fine without the script
I've tried to put a cd at the variable compile_command, so:
compile_command = f'cd {path} gfortran ucnum8.f -o ucnum8' taking out the os.chdir
Instead of: compile_command = f'gfortran ucnum8.f -o ucnum8' with the os.chdir function.
At this scenerial, the Error indicates that couldn't find the Fortran file. In this case, I undestood since the {path} were not read properly for some reason. Even though the variable path were properly created using the module os, replacing the backslashes, because of my Windows system, the path inserted in the variable compile_command seems to have been broken into parents and sons directories.
I've also used the module glob to find the files I wanted. However, the same type of error, if I'm not wrong, happened. So I prefer to maintain my usual way to access folders with the os module
I've seen this topic Error: "is not recognized as an internal or external command, operable program or batch file"
And it makes sense for me, however I'm not really in depth of how this all works. Do you have any suggestion? Making the adjustments in the topic above is needed? I appreciate your time to help me