yet another winpty binding for python
Project description
========
yawinpty
========
yet another winpty binding for python
.. image:: https://ci.appveyor.com/api/projects/status/vaa9vkgs8ihivyg9?svg=true
:target: https://ci.appveyor.com/project/TitanSnow/yawinpty
:alt: Build status
.. image:: https://img.shields.io/github/license/PSoWin/yawinpty.svg
:target: LICENSE
:alt: LICENSE
.. image:: https://img.shields.io/pypi/v/yawinpty.svg
:target: https://pypi.org/project/yawinpty
:alt: PyPI version
.. image:: https://img.shields.io/pypi/status/yawinpty.svg
:target: https://pypi.org/project/yawinpty
:alt: Development status
.. image:: https://img.shields.io/pypi/dm/yawinpty.svg
:target: https://pypi.org/project/yawinpty
:alt: Download per month
.. image:: https://img.shields.io/pypi/wheel/yawinpty.svg
:target: https://pypi.org/project/yawinpty
:alt: wheel
.. image:: https://img.shields.io/pypi/pyversions/yawinpty.svg
:target: https://pypi.org/project/yawinpty
:alt: Support python versions
install
=======
.. code-block:: bash
pip install yawinpty
build from source
===============
python 3.5+
install `Visual C++ 2015 Build Tools`_, then use ``python setup.py build`` to build
older python
+----------+-----------------------+
|Visual C++|CPython version |
+==========+=======================+
|10.0 |3.3, 3.4 |
+----------+-----------------------+
|9.0 |2.6, 2.7, 3.0, 3.1, 3.2|
+----------+-----------------------+
install *both* `Visual C++ 2015 Build Tools`_ and the matching version of Visual C++ Build Tools. open "Visual C++ *2015* Build Tools Command Prompt" with the same arch as python, then use ``python setup.py build`` to build
.. _`Visual C++ 2015 Build Tools`: http://landinghub.visualstudio.com/visual-cpp-build-tools
basic example
=============
.. code-block:: python
from yawinpty import *
with Pty() as pty:
pty.spawn(SpawnConfig(SpawnConfig.flag.auto_shutdown, cmdline='python -c "print(\'HelloWorld!\')"'))
with open(pty.conout_name(), 'r') as f:
print(f.read())
using ``yawinpty``
==================
the common goal to use ``yawinpty`` is to open a pseudo terminal then spawn a process in it and send input to it's stdin and get output from it's stdout. yawinpty.Pty wrapper a pseudo-terminal and do the jobs
*class* yawinpty.\ *Pty*\ (*config=yawinpty.Config()*)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
yawinpty.Pty accept a instance of yawinpty.Config as its config
*class* yawinpty.\ *Config*\ (:emphasis:`\*flags`)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
for the flags to init a "config class" is commonly a set of Class.flag.\*. example\:
.. code-block:: python
cfg = yawinpty.Config(yawinpty.Config.flag.plain_output)
``help(yawinpty.Config.flag)`` for more supported flags
for ``yawinpty.SpawnConfig`` it's similar
``help(yawinpty.Config)`` for more methods
instances of the ``Pty`` class have the following methods\:
Pty.\ *conin_name*\ ()
>>>>>>>>>>>>>>>>>>>>>>
Pty.\ *conout_name*\ ()
>>>>>>>>>>>>>>>>>>>>>>>
Pty.\ *conerr_name*\ ()
>>>>>>>>>>>>>>>>>>>>>>>
get the name of console in/out/err pipe. the name could be passed to builtin ``open`` to open the pipe
Pty.\ *agent_process_id*\ ()
>>>>>>>>>>>>>>>>>>>>>>>>>>>>
get the process id of the agent process
Pty.\ *set_size*\ ()
>>>>>>>>>>>>>>>>>>>>
set window size of the terminal
Pty.\ *spawn*\ (\ *spawn_config*\ )
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
spawn a process in the pty. spawn_config is a instance of ``yawinpty.SpawnConfig``. note that one Pty instance could only spawn once otherwise ``yawinpty.RespawnError`` would be raised
returns a tuple of *process id, thread id* of spawned process
*class* yawinpty.\ *SpawnConfig*\ (:emphasis:`\*spawnFlags, appname=None, cmdline=None, cwd=None, env=None`)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
``spawnFlags``
the flags from ``yawinpty.SpawnConfig.flag``
``appname``
full path to executable file. can be ``None`` if ``cmdline`` is specified
``cmdline``
command line passed to the spawned process
``cwd``
working directory for the spawned process
``env``
the environ for the spawned process, a dict like ``{'VAR1': 'VAL1', 'VAR2': 'VAL2'}``
note that init a ``SpawnConfig`` *does not* spawn a process. a process is spawned only when calling ``Pty.spawn()``. one SpawnConfig instance could be used multitimes
Pty.\ *wait_agent*\ (\ *timeout = yawinpty.INFINITE*\ )
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Pty.\ *wait_subprocess*\ (\ *timeout = yawinpty.INFINITE*\ )
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
wait for agent/spawned process to exit. raise yawinpty.TimeoutExpired if out of timeout
Pty.\ *close*\ ()
>>>>>>>>>>>>>>>>>
kill processes not exited, close pty and release Windows resource
exceptions
>>>>>>>>>>
all winpty related exceptions are subclasses of ``yawinpty.WinptyError``. ``help(yawinpty)`` for more information
yawinpty
========
yet another winpty binding for python
.. image:: https://ci.appveyor.com/api/projects/status/vaa9vkgs8ihivyg9?svg=true
:target: https://ci.appveyor.com/project/TitanSnow/yawinpty
:alt: Build status
.. image:: https://img.shields.io/github/license/PSoWin/yawinpty.svg
:target: LICENSE
:alt: LICENSE
.. image:: https://img.shields.io/pypi/v/yawinpty.svg
:target: https://pypi.org/project/yawinpty
:alt: PyPI version
.. image:: https://img.shields.io/pypi/status/yawinpty.svg
:target: https://pypi.org/project/yawinpty
:alt: Development status
.. image:: https://img.shields.io/pypi/dm/yawinpty.svg
:target: https://pypi.org/project/yawinpty
:alt: Download per month
.. image:: https://img.shields.io/pypi/wheel/yawinpty.svg
:target: https://pypi.org/project/yawinpty
:alt: wheel
.. image:: https://img.shields.io/pypi/pyversions/yawinpty.svg
:target: https://pypi.org/project/yawinpty
:alt: Support python versions
install
=======
.. code-block:: bash
pip install yawinpty
build from source
===============
python 3.5+
install `Visual C++ 2015 Build Tools`_, then use ``python setup.py build`` to build
older python
+----------+-----------------------+
|Visual C++|CPython version |
+==========+=======================+
|10.0 |3.3, 3.4 |
+----------+-----------------------+
|9.0 |2.6, 2.7, 3.0, 3.1, 3.2|
+----------+-----------------------+
install *both* `Visual C++ 2015 Build Tools`_ and the matching version of Visual C++ Build Tools. open "Visual C++ *2015* Build Tools Command Prompt" with the same arch as python, then use ``python setup.py build`` to build
.. _`Visual C++ 2015 Build Tools`: http://landinghub.visualstudio.com/visual-cpp-build-tools
basic example
=============
.. code-block:: python
from yawinpty import *
with Pty() as pty:
pty.spawn(SpawnConfig(SpawnConfig.flag.auto_shutdown, cmdline='python -c "print(\'HelloWorld!\')"'))
with open(pty.conout_name(), 'r') as f:
print(f.read())
using ``yawinpty``
==================
the common goal to use ``yawinpty`` is to open a pseudo terminal then spawn a process in it and send input to it's stdin and get output from it's stdout. yawinpty.Pty wrapper a pseudo-terminal and do the jobs
*class* yawinpty.\ *Pty*\ (*config=yawinpty.Config()*)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
yawinpty.Pty accept a instance of yawinpty.Config as its config
*class* yawinpty.\ *Config*\ (:emphasis:`\*flags`)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
for the flags to init a "config class" is commonly a set of Class.flag.\*. example\:
.. code-block:: python
cfg = yawinpty.Config(yawinpty.Config.flag.plain_output)
``help(yawinpty.Config.flag)`` for more supported flags
for ``yawinpty.SpawnConfig`` it's similar
``help(yawinpty.Config)`` for more methods
instances of the ``Pty`` class have the following methods\:
Pty.\ *conin_name*\ ()
>>>>>>>>>>>>>>>>>>>>>>
Pty.\ *conout_name*\ ()
>>>>>>>>>>>>>>>>>>>>>>>
Pty.\ *conerr_name*\ ()
>>>>>>>>>>>>>>>>>>>>>>>
get the name of console in/out/err pipe. the name could be passed to builtin ``open`` to open the pipe
Pty.\ *agent_process_id*\ ()
>>>>>>>>>>>>>>>>>>>>>>>>>>>>
get the process id of the agent process
Pty.\ *set_size*\ ()
>>>>>>>>>>>>>>>>>>>>
set window size of the terminal
Pty.\ *spawn*\ (\ *spawn_config*\ )
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
spawn a process in the pty. spawn_config is a instance of ``yawinpty.SpawnConfig``. note that one Pty instance could only spawn once otherwise ``yawinpty.RespawnError`` would be raised
returns a tuple of *process id, thread id* of spawned process
*class* yawinpty.\ *SpawnConfig*\ (:emphasis:`\*spawnFlags, appname=None, cmdline=None, cwd=None, env=None`)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
``spawnFlags``
the flags from ``yawinpty.SpawnConfig.flag``
``appname``
full path to executable file. can be ``None`` if ``cmdline`` is specified
``cmdline``
command line passed to the spawned process
``cwd``
working directory for the spawned process
``env``
the environ for the spawned process, a dict like ``{'VAR1': 'VAL1', 'VAR2': 'VAL2'}``
note that init a ``SpawnConfig`` *does not* spawn a process. a process is spawned only when calling ``Pty.spawn()``. one SpawnConfig instance could be used multitimes
Pty.\ *wait_agent*\ (\ *timeout = yawinpty.INFINITE*\ )
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Pty.\ *wait_subprocess*\ (\ *timeout = yawinpty.INFINITE*\ )
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
wait for agent/spawned process to exit. raise yawinpty.TimeoutExpired if out of timeout
Pty.\ *close*\ ()
>>>>>>>>>>>>>>>>>
kill processes not exited, close pty and release Windows resource
exceptions
>>>>>>>>>>
all winpty related exceptions are subclasses of ``yawinpty.WinptyError``. ``help(yawinpty)`` for more information
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
yawinpty-0.4.3.dev3.tar.gz
(199.1 kB
view hashes)
Built Distributions
Close
Hashes for yawinpty-0.4.3.dev3-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c3e153b1e562ae5c31b3e2d647335c1616b34189226472536cee23f6ba65b54 |
|
MD5 | 0e432c7b1943e1655c0d0a649072f1d2 |
|
BLAKE2b-256 | caa4c00081c5a52a359d7985b951f60910e39e6912660453260e31b44a93d835 |
Close
Hashes for yawinpty-0.4.3.dev3-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be463e8e59ce30a4900e912c1e79f9a6582fe7731630d41a3563708417277308 |
|
MD5 | f6a744dccd7c23dee83c88ec3b9e7267 |
|
BLAKE2b-256 | e0342fa3a110a5bbca24c0867cb9c32f107904ecba736d64749a7f04e103eef0 |
Close
Hashes for yawinpty-0.4.3.dev3-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4373dcc142f5d6498d304e2a960416da3848fea3aff329518b74f0a074ef7c8 |
|
MD5 | 3878650bd6d851f10e96e1bfb6a27776 |
|
BLAKE2b-256 | 3cfa844f23723722d1e111beb89637174a0fe0ab8f4652dd32b0965d11f6653a |
Close
Hashes for yawinpty-0.4.3.dev3-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11a8df8860236e68decc551267695676fc7edb0748ca5528cae2e3f415873505 |
|
MD5 | 6c5d8d46991281d26665a9d6f5d9f7ae |
|
BLAKE2b-256 | 8dfc7e6e03945caf9020df51ddf9f5086310a46e64385775833a1a564fdd3f8d |
Close
Hashes for yawinpty-0.4.3.dev3-cp34-cp34m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e0d561cbc15a8569283274959629f21ccf30297eba0aba9973fb774f4c212dd |
|
MD5 | 78af925b8bff52ab57b9f43ff6f0ed9f |
|
BLAKE2b-256 | 9f92fe11ccafa6d003de5fdd02bfac6f0b6343c025fa07e39785140bec00cd99 |
Close
Hashes for yawinpty-0.4.3.dev3-cp34-cp34m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd4d2fa8908d545b87f91309e246732f07de101f44691b4b29b08fb7f8a6e551 |
|
MD5 | 1a7b347ce0a1d45656eda7d4b7a3a362 |
|
BLAKE2b-256 | c8af2b9de2b40f1f6563b5d671211e1b24dab81eb19b0341f18525429cbd5009 |
Close
Hashes for yawinpty-0.4.3.dev3-cp27-cp27m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96acc4d63a8b3de641edcc3ad37dcad69a84bf63d5ec9c551ef7fd0274fcfc8c |
|
MD5 | 2d7cfbf08544f833d91bf6eb840e49c0 |
|
BLAKE2b-256 | a82ea385e0b996d0f9baa6ce9dee4e75dedc54dfe22379787ad01d8a4e39fad1 |
Close
Hashes for yawinpty-0.4.3.dev3-cp27-cp27m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7bd6ff9e72c261c07fd8685949fb6543c8a1e46100e826ac74645671fb48c21c |
|
MD5 | ae51f9fb8723d59f230dcf007134e75d |
|
BLAKE2b-256 | 8989abea454a00fb0df1acdda1b4503d47fb3f232ea626d2396f1065fa801eb2 |