[Python-Dev] #! magic (original) (raw)

Christian Heimes lists at cheimes.de
Sun Jan 20 19:30:03 CET 2008


Oleg Broytmann wrote:

A shell has nothing to do with it as it is the OS (exec system call) that upon reading the magic of the file sees #! and executes the program (up to the first space) and pass to the program the first (and the only) parameter.

#! /usr/bin/env python -O [trying to execute the script on Linux] /usr/bin/env: python -O: No such file or directory Oleg.

Oh right. I was sure that I've seen a shebang with options somewhere. It might have been a shell script or a perl script.

Yet another python executable could solve the issue, named "pythons" as python secure.

/* gcc -DNDEBUG -g -O2 -Wall -Wstrict-prototypes -IInclude -I. -pthread -Xlinker -lpthread -ldl -lutil -lm -export-dynamic -o pythons2.6

pythons.c libpython2.6.a */

#include "Python.h"

int main(int argc, char *argv) { / disable some possible harmful features */ Py_IgnoreEnvironmentFlag++; Py_NoUserSiteDirectory++; Py_InteractiveFlag -= INT_MAX; Py_InspectFlag -= INT_MAX;

    return Py_Main(argc, argv);

}

$ ./pythons2.6 Python 2.6a0 (:59956M, Jan 14 2008, 22:09:17) [GCC 4.2.1 (Ubuntu 4.2.1-5ubuntu4)] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import sys sys.flags sys.flags(debug=0, py3k_warning=0, division_warning=0, division_new=0, inspect=-2147483647, interactive=-2147483647, optimize=0, dont_write_bytecode=0, no_user_site=1, no_site=0, ingnore_environment=1, tabcheck=0, verbose=0, unicode=0)

Christian



More information about the Python-Dev mailing list