I'm trying to run this script, I got it from here ( http://www.tutorialspoint.com/python/os_mknod.htm ) I use OS: OSX EL Capitan v.10.11.2, Python: 2.7.10:
# !/usr/bin/python
import os
import stat
filename = '/tmp/tmpfile'
mode = 0600|stat.S_IRUSR
# filesystem node specified with different modes
os.mknod(filename, mode)
running it in the terminal without sudo (python testOs.py) returns me:
Traceback (most recent call last):
File "testOs.py", line 10, in <module>
os.mknod(filename, mode)
OSError: [Errno 1] Operation not permitted
and running it with sudo (sudo python testOs.py):
Traceback (most recent call last):
File "testOs.py", line 10, in <module>
os.mknod(filename, mode)
OSError: [Errno 22] Invalid argument
What am I doing wrong ? What are the correct arguments or where is the error ?
To me, works perfectly. The script is fine.
You'll have to look for the error outside of the script.
I have tried to reproduce your error, but I have not succeeded.
Removing permissions to /tmp:
Creating the file before:
Please update your question with:
python --version
ls -l / | grep tmp
ls -l /tmp | grep tmpfile
before and after executing the script.I have tried with Ubuntu 15.10 and Python 2.7.10
Updated after edit :
Sure enough, the problem is outside of the script. Apparently this has to do with System Integrity Protection .
In this answer in English they explain how to deactivate it; But I'm not so sure that's a good idea.
I don't have OSX ElCapitan and I can't help you anymore.
Strange use of stat.S_IRUSR
S_IRUSR
means that the user has read permission.It's weird that you OR
0600
S_IRUSR because0600
it already includes that permission.You can check it with this code:
Which in my case gives as output: