1

I have a Python script that uses csv.writer to create a csv file. This works fine when I run it from the command line, but no file is created when I run the script using Windows Task Scheduler. The only thing I can think of is that I'm not running my computer as admin (because it's a work computer), but why would it let me do this on command line but not in Scheduler? The rest of the script runs with Scheduler, just not the csv file saving part.

7
  • Try to change the task's user under which it runs. Also, you haven't mentioned or tagged what Windows / OS you're using.
    – JasonXA
    Commented Apr 17, 2015 at 15:01
  • I can't change the user because I am on a work computer. I'm using Windows 7.
    – Abbie
    Commented Apr 17, 2015 at 15:52
  • @Abbie let me rewrite your script to powershell or WSH)
    – STTR
    Commented Apr 17, 2015 at 17:41
  • No Abbie, when setting up the task, in the properties there's a user under which it can run, try to change that. It's under the General tab as posted below in the screenshot. If you run as a limited user, then the write operations might fail just because there are no relevant privileges for the operation. Try to run it under your user and make sure the csv file is written to a location where you're allowed to write.
    – JasonXA
    Commented Apr 18, 2015 at 10:57
  • I was already running it under my user profile. What I don't understand is that there aren't privilege problems writing the csv file when I run this script myself from the command line but, when I use Task Scheduler, it doesn't write the csv file.
    – Abbie
    Commented Apr 20, 2015 at 8:10

2 Answers 2

3

I used this to solve a similar problem. Under your batch action I set it up as the following and it worked fine for me.

  • Program/script: path to python, e.g., C:\Python27\ArcGIS10.2\python.exe
  • Add Arguments (optional): script name, e.g., scrape.py
  • Start in (optional): path to script, e.g., C:\Users\handsome\Documents\PYTHON\Code
-2

Program/script: cmd arg: "/c C:\Python27\python.exe C:\Script\script.py"

enter image description here

2
  • 2
    You got the downvotes because you didn't put the least bit of effort into your answer. All you did was drop some cryptic command without explaining what it is or what to do with it. It took me more time to understand your answer than it did to understand the poster's question, and the only reason I spent that time was because it came up in the Low Quality Posts review queue. I edited your answer to make it more clear. All I did was add a screenshot that took me less than 30 seconds to make.
    – Wes Sayeed
    Commented Apr 17, 2015 at 22:26
  • Thanks for the suggestion (and the added screenshots). I tried this way but, when I pressed Run, the command box opened for half a second then closed and it didn't look like anything happened.
    – Abbie
    Commented Apr 20, 2015 at 8:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .