I usually execute a Fortran file on Linux (manually) as:
- Server connection
- Go to the special folder
ifort xxx.for -o xxx && ./xxx (where "xxx.for" is my Fortran file and "xxx" is the Fortran executable)
But I need to call my fortran file (xxx.for) from python (I am new), so I used subprocesswith the following command:
cmd = ["ssh", sshConnect, "cd %s;"%(workDir), Fortrancmd %s jobname "%s -o %s" exeFilename "%s && %s ./ %s%s"%(exeFilename)]
But I get an error message, and I'm not sure what happened. Here is the full code:
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)]
**
**
**#example:ifort xxx.for -o xxx && ./xxx (press enter)
print cmd
How can I write a python program that performs all three steps described above and avoids the error I get?
pear
source
share