Thanks, everyone. I am writing a script to execute multiple command in command line. It is one part of my whole script.
I have checked many answers, but none of them solved my problem. Some of them are too old to use.
My commands are like this
cd C:/Users/Bruce/Desktop/test set I_MPI_ROOT=C:\Program Files\firemodels\FDS6\bin\mpi set PATH=%I_MPI_ROOT%;%PATH% fds_local -o 1 -p 1 test.fds python test.py
I tried to use subprocess.run or os.system, etc. But they do not work. I don't know what happened. Here is an example I have used.
file_path = "C:/Users/Bruce/Desktop/test" cmd1 = 'cd ' + file_path cmd2 = "set I_MPI_ROOT=C:/Program Files/firemodels/FDS6/bin/mpi" cmd3 = "set PATH=%I_MPI_ROOT%;%PATH%" nMPI = '-p {}'.format(1) nOpenMP = '-o {}'.format(1) cmd4 = "fds_local {} {} ".format(nMPI, nOpenMP) + file_name cmd = '{} && {} && {} && {}'.format(cmd1, cmd2, cmd3, cmd4) subprocess.Popen(cmd, shell=True)
I am not quite familiar with subprocess. But I have worked for one week to solve this problem. It makes me crazy. Any suggestions?