Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python script works fine on Linux, on Windows, causes WindowsError: [Error 5] Access is denied

I have a simple python script that works fine on Linux, I moved it to a Windows machine and when I attempt to run it, I get the following exception message:

Traceback (most recent call last):
  File "C:\path\to\my\script.py", line 57, in <module>
    retcode = subprocess.call(command)
  File "C:\Python27\lib\subprocess.py", line 493, in call
    return Popen(*popenargs, **kwargs).wait()
  File "C:\Python27\lib\subprocess.py", line 679, in __init__
    errread, errwrite)
  File "C:\Python27\lib\subprocess.py", line 893, in _execute_child
    startupinfo)
WindowsError: [Error 5] Access is denied

Here is the snippet of code that throws the exception:

print 'command is:',command
retcode = subprocess.call(command)

The console out put is as follows:

command is: ['c:\python27', 'C:\path\to\script.py', '--mode=2', '--check-temp=false', '--all-seasons=true', '--added=1', '--max-temp=2000', '--source=2', '--loc=XYZ'] Unhandled exception while debugging...

Anyone knows how to fix this?

I am running python v2.7.3 on Windows XP Professional

like image 504
johnsmith Avatar asked Feb 19 '26 17:02

johnsmith


1 Answers

According to the documentation, the first item in the argument sequence (in this case, the first element of command) is interpreted as the program to execute.

Looking at the first element of command, it would appear that you're trying to execute a directory. Windows (somewhat non-intuitively) returns an access denied error whenever you try to read from a directory as if it were a file, and the same thing happens if you try to execute one.

Instead of c:\python27 you probably want c:\python27\bin\python.exe or something similar. At any rate, you need to be pointing at the executable, not at the directory. I'm not sure why this works for you on Linux.

like image 70
Harry Johnston Avatar answered Feb 21 '26 06:02

Harry Johnston



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!