我通常在Linux(手动)中执行Fortran文件:
连接到服务器
转到特定文件夹
ifort xxx.for -o xxx && ./xxx
(其中'xxx.for'是我的Fortran文件,'xxx'是Fortran可执行文件)
但我需要从python(我是初学者)调用我的fortran文件(xxx.for),所以我使用subprocess
以下命令:
cmd = ["ssh", sshConnect, "cd %s;"%(workDir), Fortrancmd %s jobname "%s -o %s" exeFilename "%s && %s ./ %s%s"%(exeFilename)]
但我得到一个错误,我不确定是什么问题.这是完整的代码:
import string import subprocess as subProc from subprocess import Popen as ProcOpen from subprocess import PIPE import numpy import subprocess userID = "pear" serverName = "say4" workDir = "/home/pear/2/W/fortran/" Fortrancmd = "ifort" jobname = "rad.for" exeFilename = "rad" sshConnect=userID+"@"+servername cmd=["ssh", sshConnect, "cd %s;"%(workDir), Fortrancmd %s jobname "%s -o %s" exeFilename "%s && %s ./ %s%s"%(exeFilename)] **#command to execute fortran files in Linux **#ifort.for -o && ./ (press enter) **#example:ifort xxx.for -o xxx && ./xxx (press enter) print cmd
如何编写一个执行上述所有3个步骤的python程序并避免我得到的错误?