开发者

Python script runs with double-click and IDLE but not windows CMD shell

I'm have a problem where if I double click my script (.py), or open it with IDLE, it will compile and run correct. However, if I try to run the script in my windows command line, using

C:\> "C:\Software_Dev\Python 2.7.1\python.exe" C:\path\to\script\script.py

I get...

Traceback (most recent call last):
  File "C:\path\to\script\script.py", line 66, in <module>
    a.CheckTorrent()
  File "C:\path\to\script\script.py", line 33, in script
    self.WriteLog(fileName)
  File "C:\path\to\script\script.py", line 54, in WriteLog
    myFile = open(r'%s' %(filename), 'w')
IOError: [Errno 13] Permission denied开发者_如何学Python: './TorrentMonitor.log' 

So my question is, why am I getting permission errors when I run this script through command line in window 7 but not when I double click? What's the difference between those two processes?

Thanks in advance!


The script is trying to write into a file in the current directory. In the example above, you're starting it from C:\ where you probably don't have write permissions.

cd to a directory that you own, and you should be able to run that command just fine.


This is because when you double-click the file (or when running it from IDLE), the current working directory is the directory that contains your script. When starting it from the command line, it's C:\ which you don't seem to have write access to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜