Feb-20-2018, 09:40 AM
(This post was last modified: Feb-20-2018, 09:40 AM by Gribouillis.)
You can perhaps run this shell script at launch time: it creates a python file then uses exec to run it and the python file destroys itself in the end
EDIT: Better version:
#!/bin/bash read -r -d '' SPAM << ENDOFCODE def hi(): print('hello world') hi() import os os.remove(__file__) ENDOFCODE echo "$SPAM" > /tmp/spam.py exec /usr/bin/python3 /tmp/spam.pyObviously you can run an arbitrary python script with this. You can also improve this my using
mktemp
to name the python script.EDIT: Better version:
#!/bin/bash PYFILE=$(mktemp --suffix=.py) cat << ENDOFCODE > $PYFILE def hi(): print('hello world') hi() import os print('removing:', __file__) os.remove(__file__) ENDOFCODE exec /usr/bin/python3 $PYFILEEDIT: In this last version, there isn't even a temporary file
#!/bin/bash cat << ENDOFCODE | exec /usr/bin/python3 -c "import sys; exec(sys.stdin.read())" def hi(): print('hello world') hi() ENDOFCODEYou can remove the word exec if you don't mind that your python script executes with a different pid.