title: WinError 2 The system cannot find the file specified (Python)
body: <p>I have a Fortran program and want to execute it in python for multiple files. I have 2000 input files but in my Fortran code I am able to run only one file at a time. How should I call the Fortran program in python?</p>
  
  <p><strong>My Script:</strong></p>
  
  <pre><code>import subprocess
  import glob
  input = glob.glob('C:/Users/Vishnu/Desktop/Fortran_Program_Rum/*.txt')
  output = glob.glob('C:/Users/Vishnu/Desktop/Fortran_Program_Rum/Output/')
  f = open("output", "w")
  for i in input:
      subprocess.Popen(["FORTRAN ~/C:/Users/Vishnu/Desktop/Fortran_Program_Rum/phase1.f", "--domain "+i])
  f.write(i)
  </code></pre>
  
  <p><strong>Error:</strong></p>
  
  <pre><code>runfile('C:/Users/Vishnu/Desktop/test_fn/test.py', wdir='C:/Users/Vishnu/Desktop/test_fn')
  Traceback (most recent call last):
  
     File "&lt;ipython-input-3-f8f378816004&gt;", line 1, in &lt;module&gt;
  runfile('C:/Users/Vishnu/Desktop/test_fn/test.py', wdir='C:/Users/Vishnu/Desktop/test_fn')
  
    File "C:\Users\Vishnu\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
  execfile(filename, namespace)
  
    File "C:\Users\Vishnu\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
  exec(compile(f.read(), filename, 'exec'), namespace)
  
    File "C:/Users/Vishnu/Desktop/test_fn/test.py", line 30, in &lt;module&gt;
  subprocess.Popen(["FORTRAN ~/C:/Users/Vishnu/Desktop/Fortran_Program_Rum/phase1.f", "--domain "+i])
  
    File "C:\Users\Vishnu\Anaconda3\lib\subprocess.py", line 707, in __init__
  restore_signals, start_new_session)
  
    File "C:\Users\Vishnu\Anaconda3\lib\subprocess.py", line 990, in _execute_child
  startupinfo)
  
  FileNotFoundError: [WinError 2] The system cannot find the file specified
  </code></pre>
  
  <p><strong>Edit:</strong></p>
  
  <pre><code>import subprocess
  import os
  input = os.path.normcase(r'C:/Users/Vishnu/Desktop/Fortran_Program_Rum/*.txt')
  output = os.path.normcase(r'~/C:/Users/Vishnu/Desktop/Fortran_Program_Rum/Output/')
  f = open("output", "w")
  for i in input:
      exe = os.path.normcase(r'~/C:/Program Files (x86)/Silverfrost/ftn95.exe')
      fortran_script = os.path.normcase(r'~/C:/Users/Vishnu/Desktop/test_fn/test_f2py.f95')
      i = os.path.normcase(i)
      subprocess.Popen([exe, fortran_script, "--domain", i])
      f.write(i)
  </code></pre>
  
  <p><strong>Error:</strong></p>
  
  <pre><code>FileNotFoundError: [WinError 2] The system cannot find the file specified
  </code></pre>
  
  <p><strong>Edit - 2:</strong></p>
  
  <p>I have change my script as below: but error is same</p>
  
  <pre><code>input = os.path.normcase(r'C:/Users/Vishnu/Desktop/Fortran_Program_Rum/*.txt')
  output = os.path.normcase(r'C:/Users/Vishnu/Desktop/Fortran_Program_Rum/Output/')
  f = open("output", "w")
  for i in input:
      exe = os.path.normcase(r'C:/Program Files (x86)/Silverfrost/ftn95.exe')
      fortran_script = os.path.normcase(r'C:/Users/Vishnu/Desktop/test_fn/test_f2py.f95')
      i = os.path.normcase(i)
      subprocess.Popen([exe, fortran_script, "--domain", i])
      f.write(i)
  </code></pre>
  
  <p><strong>Error: 2</strong></p>
  
  <pre><code>FileNotFoundError: [WinError 2] The system cannot find the file specified
  </code></pre>
  
  <p><strong>Error: 3 - 15-03-2017</strong></p>
  
  <pre><code>import subprocess
  import os
  input = os.path.normcase(r'C:/Users/Vishnu/Desktop/Fortran_Program_Rum/*.txt')
  output = os.path.normcase(r'C:/Users/Vishnu/Desktop/Fortran_Program_Rum/Output/')
  f = open('output', 'w+')
  for i in input:
      exe = os.path.normcase(r'C:/Program Files (x86)/Silverfrost/ftn95.exe')
      fortran_script = os.path.normcase(r'C:/Users/Vishnu/Desktop/Fortran_Program_Rum/phase1.f')
      i = os.path.normcase(i)
      subprocess.Popen([exe, fortran_script, "--domain", i], shell = True)
      f.write(i)
  </code></pre>
  
  <p>** Error **</p>
  
  <pre><code>PermissionError: [Errno 13] Permission denied: 'output'
  </code></pre>