summaryrefslogtreecommitdiff
path: root/code/snippets/exec_python.rb
blob: b60d0b13adb1787510a171a6dc0296fd528147bc (plain)
1
2
3
4
5
6
7
8
hosts = File.open('/etc/hosts')

python_code = %Q[import os; print os.fdopen(#{hosts.fileno}).read()]

# The hash as the last arguments maps any file descriptors that should 
# stay open through the exec.
exec 'python', '-c', python_code, {hosts.fileno => hosts}