Created
November 28, 2023 12:11
-
-
Save pkubik/fcf388960dc1977320059b2460e35756 to your computer and use it in GitHub Desktop.
Daemonized python interpreter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# setup FIFO and hang python interpreter | |
fifo_path=$TMPDIR/"pysh-"$(date +%s) | |
mkfifo $fifo_path | |
python3 <$fifo_path & | |
exec 3>$fifo_path | |
# perform some commands | |
echo 'import os' >$fifo_path | |
cat >$fifo_path <<EOF | |
import json | |
print(json.dumps( | |
{str(i): i for i in range(5)} | {"path": os.environ.get("PATH")}, | |
indent=4, | |
)) | |
EOF | |
# clean up | |
exec 3>&- | |
rm $fifo_path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment