From db1191ec0e7305d684383f8974e2fa437f77ad5a Mon Sep 17 00:00:00 2001 From: mo khan Date: Wed, 28 Aug 2013 07:20:13 -0600 Subject: initial commit --- code/snippets/exec_python.rb | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 code/snippets/exec_python.rb (limited to 'code/snippets/exec_python.rb') 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} + -- cgit v1.2.3