Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e214baa

Browse files
committed
Fix binfmt_register documentation to always register the right magic.
1 parent 4e3f275 commit e214baa

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

Misc/NEWS

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,10 @@ Core language, builtins, and interpreter
259259
- The interpreter accepts now bytecode files on the command line even
260260
if they do not have a .pyc or .pyo extension. On Linux, after executing
261261

262-
echo ':pyc:M::\x87\xc6\x0d\x0a::/usr/local/bin/python:' > /proc/sys/fs/binfmt_misc/register
262+
import imp,sys,string
263+
magic = string.join(["\\x%.2x" % ord(c) for c in imp.get_magic()],"")
264+
reg = ':pyc:M::%s::%s:' % (magic, sys.executable)
265+
open("/proc/sys/fs/binfmt_misc/register","wb").write(reg)
263266

264267
any byte code file can be used as an executable (i.e. as an argument
265268
to execve(2)).

0 commit comments

Comments
 (0)