Skip to content

Instantly share code, notes, and snippets.

@NiceRath
Created August 27, 2024 12:32
Show Gist options
  • Save NiceRath/50e2ae549f4789c95d10c23ada20948d to your computer and use it in GitHub Desktop.
Save NiceRath/50e2ae549f4789c95d10c23ada20948d to your computer and use it in GitHub Desktop.
Python3 - Write to OS pipe /dev/fd/
#!/usr/bin/env python3
# this can be useful in CI environments if you need to process config or secrets and pipe them to the parent process in a secure manner
import io
import os
from time import sleep
w = io.open(69, 'wb', 0)
w.write(b'MY SECRE3T')
w.flush()
# print(os.listdir('/dev/fd/'))
# parent process can read the output like this:
# python3 test.py 69> test.txt
# or redirect it to default stdout
# python3 test.py 69>&1 1>/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment