Commit 1631def1 authored by Luke Macken's avatar Luke Macken

Add a new pyrasite-shell tool. Give it a pid, get a prompt.

parent dc7a8469
......@@ -20,4 +20,27 @@ pyrasite - A command-line interface for injecting code into running Python proce
For updates, visit https://github.com/lmacken/pyrasite
pyrasite-shell
--------------
You can easily open up a shell and execute commands in a running process using
the `pyrasite-shell`.
.. code-block:: bash
$ pyrasite-shell
Usage: pyrasite-shell <PID>
.. code-block:: bash
$ pyrasite-shell $(pgrep -f "python -v")
Pyrasite Shell 2.0beta7
Python 2.7.2 (default, Oct 27 2011, 01:40:22)
[GCC 4.6.1 20111003 (Red Hat 4.6.1-10)] on linux2
>>> print(x)
foo
>>> globals()['x'] = 'bar'
.. seealso:: :doc:`Payloads`
# This file is part of pyrasite.
#
# pyrasite is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pyrasite is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pyrasite. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2012 Red Hat, Inc., Luke Macken <lmacken@redhat.com>
import sys
import pyrasite
def shell():
"""Open a Python shell in a running process"""
if not len(sys.argv) == 2:
print("Usage: pyrasite-shell <PID>")
sys.exit(1)
pid = int(sys.argv[1])
ipc = pyrasite.PyrasiteIPC(pid)
ipc.connect()
print("pyrasite shell %s" % pyrasite.__version__)
print(ipc.cmd('import sys; print("Python " + sys.version + ' +
'" on " + sys.platform)'))
try:
while True:
print(ipc.cmd(raw_input('>>> ')))
except:
pass
ipc.close()
print()
......@@ -25,6 +25,7 @@ setup(name='pyrasite',
[console_scripts]
pyrasite = pyrasite.main:main
pyrasite-memory-viewer = pyrasite.tools.memory_viewer:main
pyrasite-shell = pyrasite.tools.shell:shell
""",
classifiers=[
'Development Status :: 4 - Beta',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment