title: Can't seem to get fortran executable to run correctly through python
body: <p>I have read a bunch of different topics on SO and other sites and cannot get a direct answer to my question/problem. Currently I have this python script that runs completely fine, with the exception of no calls made to run a fortran program are working correctly. I have tried using subprocess commands, os.system commands, opening bash script files that are opened through python, and no luck. Here are some examples and errors I'm getting. </p>
  
  <p>One attmept:</p>
  
  <pre><code>subprocess.Popen(["sh", "{0}{1}".format(SCRIPTS,"qlmtconvertf.sh"), "qlmt"], shell=False, stdout=subprocess.PIPE)
  </code></pre>
  
  <p>This gives an error that the program has trouble reading the file correctly.</p>
  
  <pre><code>    forrtl: severe (24): end-of-file during read, unit 1, file /home/akoufos/lapw/Ar/lda/bcc55_mt1.5_lo_e8_o4/DOS/lat70/qlmt
  </code></pre>
  
  <p>Another attempt:</p>
  
  <pre><code>subprocess.Popen(["./{0}{1}".format(SOURCE,"qlmtconvertf"), "qlmt"], shell=False, stdout=subprocess.PIPE)
  </code></pre>
  
  <p>This gives an error of not finding the file.</p>
  
  <pre><code>    File "/home/akoufos/lapw/Scripts_Plots/LAPWanalysis.py", line 59, in DOS
  subprocess.Popen(["./{0}{1}".format(SOURCE,"qlmtconvertf"), "qlmt"], shell=False, stdout=subprocess.PIPE)
      File "/usr/lib64/python2.7/subprocess.py", line 672, in __init__
  errread, errwrite)
      File "/usr/lib64/python2.7/subprocess.py", line 1202, in _execute_child
  raise child_exception
      OSError: [Errno 2] No such file or directory
  </code></pre>
  
  <p>Yet another attempt:</p>
  
  <pre><code>os.system("{0}{1}".format(SOURCE,"qlmtconvertf qlmt"))
  </code></pre>
  
  <p>This gives an error equivalent to the first example. In all examples SOURCE="/home/myusername/lapw/Source/", where the fortran source files are, SCRIPTS="/home/myusername/lapw/Scripts_Plots/", where I have other files and the python scripts in, qlmtconvertf is a compiled fortran program, and qlmt is a file the qlmtconvertf reads. This source code works completely fine if I call it in the shell, like I have done countless times, but I'm trying to automate calling these codes. I have written a bash script as well, that does what I need, but I'm trying to do everything through python instead. Any ideas, suggestions, or answers to what I am doing incorrectly and what is going on would be greatly appreciated. Thank you all in advance.</p>
  
  <p><strong>EDIT:</strong> I got it working with the suggestion given below by Francis. I had to keep the complete paths (i.e. /home/username/etc) and the <code>os.path.join</code> to call the program correctly.</p>
  
  <pre><code>    import os.path
      LAPW = "/home/myusername/lapw/"
      SOURCE = os.path.join(LAPW,'Source')
      SCRIPTS = os.path.join(LAPW,'Scripts_Plots')
      QLMTCONVERT = os.path.join(SOURCE,'qlmtconvertf')
      qargs = [QLMTCONVERT,'qlmt']
      #CALLING PROGRAM
      subprocess.Popen(qargs, stdout=subprocess.PIPE).communicate(input=None)
  </code></pre>
  
  <p>To get it to work correctly I had to also close the 'qlmt' file I had created during the python script. Also I am working in the directory that contains the 'qlmt' file. </p>
  
  <p>(<strong>edit</strong> Also added <code>.communicate(input=None)</code> to the end of the subprocess. This was unnecessary for this process call, but it was important for a latter one I made in the script that tried to use a file the process was creating. From my understanding the <code>.communicate</code> talks to the process and basically waits for it to finish before the next python line is executed. Similar to <code>.wait()</code>, but more advanced. If someone who understands this more wants to elaborate, please feel free. <strong>edit</strong>) </p>
  
  <p>I'm not exactly sure why this method worked, but using strings as inputs for the subprocess was giving errors. If any one has any insight on this I would be very thankful if you could pass on your knowledge. Thank you everyone for the help. </p>