title: Scheduling a Python Script via Windows Task Scheduler
body: <p>Observe the following Python script, "Script.py":</p>
  
  <pre><code>import subprocess
  src_directory = 'Z:\z_7z\Some_Directory'
  zip_file_name = 'Test.7z'
  cmd = ['7z', 'a', zip_file_name, src_directory, '-mx9']
  subprocess.Popen(cmd, stderr = subprocess.STDOUT, stdout = subprocess.PIPE)
  </code></pre>
  
  <p>My intent is to schedule a Python script using Windows Task Scheduler.  I have successfully done this using other Python scripts before.  However, I am unable to execute the script shown above via scheduling.  I am unsure as to whether this is a Windows Task Scheduler problem or a Python problem, but here is what I know:</p>
  
  <p>"Script.py", as shown above, is a script for running a 7zip compression on a "Some_Directory" directory.  The script itself and the 7z.exe application which it is invoking are both stored in the "Y:\z_7z" directory.</p>
  
  <p>The script seems to be working fine when executed manually.  I can double-click on the script and it will execute properly.  Also, I can execute the script from the command line via the following command:</p>
  
  <pre><code>Y:\z_7z\Script.py
  </code></pre>
  
  <p>However, I cannot execute the script manually by navigating to the "C:\Python27" directory and attempting the following:</p>
  
  <pre><code>python Y:\z_7z\Script.py
  </code></pre>
  
  <p>This yields the following error:</p>
  
  <pre><code>Line 5 in module subprocess.Popen(cmd, stderr = subprocess.STDOUT, ...)
  WindowsError: [Error 2] The system cannot find the file specified
  </code></pre>
  
  <p>Provided all of that information, the real problem I am having is that Windows Task Scheduler cannot execute this script (Last Run Result = 0x1).  I have tried various Windows Task Scheduler configurations, including the one which seems to be ideal which goes as follows:</p>
  
  <ul>
  <li>Program/script: "C:\Python27\python.exe"</li>
  <li>Add arguments (optional): "Y:\z_7z\Script.py"</li>
  <li>Run whether user is logged on or not</li>
  </ul>
  
  <p>Again, I have scheduled other Python scripts before which have run successfully.  This Windows Task Scheduler task seems to be configured properly.  I browsed through some of the more advanced settings and did not find anything suspicious with this particular task.</p>