diff options
| author | mo khan <mo@mokhan.ca> | 2013-08-28 07:20:13 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2013-08-28 07:20:13 -0600 |
| commit | db1191ec0e7305d684383f8974e2fa437f77ad5a (patch) | |
| tree | 5e27b197dff849d22d8e1f50eb75aa499b16bd06 /code/snippets/exec_python.rb | |
Diffstat (limited to 'code/snippets/exec_python.rb')
| -rw-r--r-- | code/snippets/exec_python.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/code/snippets/exec_python.rb b/code/snippets/exec_python.rb new file mode 100644 index 0000000..b60d0b1 --- /dev/null +++ b/code/snippets/exec_python.rb @@ -0,0 +1,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} + |
