FilcekNA
FilcekNA

Reputation: 1

os.system('source' + fortrancommand) unable to find file

I am fairly new to linux and am installing a program initially made for mac on a linux computer (Ubuntu 3.10.0-1160.49.1.el7.x86_64 kernel). It starts with a python program that generates and then calls Fortran subprograms using

os.system('source ' + fortrancommand)

but I keep getting the error sh: line 0: source: fortrancommand: file not found. Even when I use a print statement the line before to double check the pathing to the command is correct, os.system cannot find it.

I tried replacing things with subproccesses, as the answer to similar problems suggests, but I can't get those working calling a fortran command that isn't precompiled (i.e, couldn't find a way to write out and then compile to run the fortran code). I am using Fortran77 and python 2.7 to match compatibility to the original program.

Here is a short piece of code that generates the same error:

import os, sys

#creates a fortran hello world command using out_file.write
#compiles and executes created command using os.system

#setting up outfile the same way as in rotator_model.py
root = 'output_hw' #naming command
cmd = root+'.f'
outfile = open(cmd, 'w') #creating new
outfile = open(cmd, 'a') #outfile now appends to already made file

#writing hw program in it

outfile.write("      PROGRAM HELLOW \n")
outfile.write("      WRITE(UNIT=*, FMT=*) 'Hello World!'\n")
outfile.write("      END\n")

outfile.close()

os.system("source " cmd)

Why can't it find the command, when it just made it? How do I fix it while changing the least code in the original program possible? If i need to, how do I use subprocess to run this?

Upvotes: 0

Views: 38

Answers (0)

Related Questions