title: Running python script in Service account by using windows task scheduler
body: <blockquote>
    <p>NOTE 1- All files are running using cmd in my profile and fetching
    correct results.But not with the windows task scheduler.</p>
  </blockquote>
  
  <p>**> NOTE 2- I finally got a lead that glob.glob and os.listdir is not</p>
  
  <blockquote>
    <p>working in the windows task scheduler in my python script in which I
    am making a connection to a remote server, but it is working in my
    local using cmd and pycharm.**
        **</p>
  </blockquote>
  
  <pre><code>print("before for loop::", os.path.join(file_path, '*')) 
  print(glob.glob( os.path.join(file_path, '*') ))
  for filename in glob.glob( os.path.join(file_path, '*') ):
  print("after for loop")
  </code></pre>
  
  <p>**
  <strong>While running above .py script I got: <code>before for loop:: c:\users\path\dir\*</code>
  While executing <code>print(glob.glob( os.path.join(file_path, '*') ))</code> giving <code>"[]"</code> and not able to find why?</strong></p>
  
  <p>I followed this StackOverflow link for setting up Windows Scheduler for python by referring to MagTun comment:<a href="https://stackoverflow.com/questions/44727232/scheduling-a-py-file-on-task-scheduler-in-windows-10">Scheduling a .py file on Task Scheduler in Windows 10</a></p>
  
  <ol>
  <li><p>Currently, I am having <strong>scheduler.py</strong> which is calling the other 4 more .py files.</p></li>
  <li><p>When I try to run <strong>Scheduler.py</strong> from Windows Task SCHEDULER,</p></li>
  </ol>
  
  <blockquote>
    <p>It runs Scheduler.py and then after 1 minute it runs all other 4 .py files and exit within a seconds. Not giving any output in elastic search.</p>
  </blockquote>
  
  <p>I used this for cmd script:</p>
  
  <pre><code> @echo off
  cmd /k "cd /d D:\folder\env\Scripts\ &amp; activate &amp;  cd /d D:\folder\files &amp; python scheduler.py" &gt;&gt; open.log
  
  timeout /t 15
  </code></pre>
  
  <p>In this above cmd command, It is not saving anything in open.log when running with windows task scheduler.</p>
  
  <p><strong>Script with multiple .py subprocess schedulers is like this:</strong></p>
  
  <pre><code>from apscheduler.schedulers.blocking import BlockingScheduler
  import datetime
  from subprocess import call
  from datetime import datetime
  import os
  from apscheduler.schedulers.blocking import BlockingScheduler
  
  def a():
      call(['python', r'C:\Users\a.py'])
  
  def b():
      call(['python', r'C:\Users\b.py'])
  
  def c():
      call(['python', r'C:\Users\c.py'])
  
  def d():
      call(['python', r'C:\Users\d.py'])
  
  if __name__ == '__main__':
      scheduler = BlockingScheduler()
      scheduler.add_job(a, 'interval', minutes=1)
      scheduler.add_job(b, 'interval', minutes=2)
      scheduler.add_job(c, 'interval', minutes=1)
      scheduler.add_job(d, 'interval', minutes=2)
      print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
      try:
          scheduler.start()
          print("$$$$$$$$$$$$$$$$$$")
      except (KeyboardInterrupt, SystemExit):
          print("****#####")
          pass
  </code></pre>