Jean Raymond Daher
Jean Raymond Daher

Reputation: 394

Python subprocess calling

I have a problem with running files through python. This is my code :

def report1(self):
   str="/Users/Apple/Desktop/Report1.exe"
   subprocess.call(str)


This is the error i am getting : 
File "./DBMS.py", line 427, in <module>
Main().run();
File "./DBMS.py", line 415, in run
self.report1()
File "./DBMS.py", line 383, in report1
subprocess.call(str)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py",      line 524, in call
return Popen(*popenargs, **kwargs).wait()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1308, in _execute_child
raise child_exception

OSError: [Errno 13] Permission denied

PS: i tried changing permission rights on folders and i tried using subprocress.Popen . i also tried adding shell=True. i don't understand why its still not working .

any help is really appreciated. have to submit in 24 hours :(

Upvotes: 0

Views: 901

Answers (2)

Mark Williams
Mark Williams

Reputation: 678

For all its merits, subprocess doesn't make it abundantly clear when an error has occurred while trying to execute a command.

If the deepest frame in your traceback (the one right before the actual exception) is raise child_exception from subprocess.py, that means there was some issue inclusively between the fork(2) and exec*(2) calls -- in other words, that an error occurred while trying to run the command you requested.

The actual exception you pasted was OSError: [Errno 13] Permission denied. An errno of 13 corresponds to EACCES:

>>> import errno; print errno.errorcode[13]
EACCES

If you've never used fork(2) or exec(2) things will be pretty inscrutable, because subprocess has dropped the real traceback. However, I can tell you that this OSError almost certainly came from the exec* call. It turns out execve raises this under the following conditions:

 [EACCES]           Search permission is denied for a component of the
                    path prefix.

 [EACCES]           The new process file is not an ordinary file.

 [EACCES]           The new process file mode denies execute permission.

 [EACCES]           The new process file is on a filesystem mounted with
                    execution disabled (MNT_NOEXEC in <sys/mount.h>).

(Courtesy of Apple)

If I had to guess, you encountered this this exception because the command you're trying to run isn't marked executable (with something like chmod u+x).

Now, it's unlikely that your .exe file will run on your Mac after solving this, but at least it'll be a different error!

Upvotes: 1

amehta
amehta

Reputation: 1317

Try running your program as sudo:

sudo python mycode.py

Upvotes: 0

Related Questions