yet another winpty binding for python
Project description
yet another winpty binding for python
install
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
basic examples
get output from process
from yawinpty import *
# open a pty
with Pty() as pty:
# spawn a process ``python -c "print('HelloWorld!')"``
pty.spawn(SpawnConfig(SpawnConfig.flag.auto_shutdown, cmdline='python -c "print(\'HelloWorld!\')"'))
# open the out pipe of console to read
with open(pty.conout_name(), 'r') as f:
# HelloWorld!
print(f.read())
communicate with process
from yawinpty import *
with Pty() as pty:
# spawn python repl
pty.spawn(SpawnConfig(SpawnConfig.flag.auto_shutdown, cmdline='python'))
# open the in pipe of console to write
with open(pty.conin_name(), 'w') as f:
f.write('1 + 2\n')
# write EOF to exit python
f.write('\x1a\n')
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(*flags)
for the flags to init a “config class” is commonly a set of Class.flag.*. example:
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(*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.YawinptyError. 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
Built Distributions
Hashes for yawinpty-0.4.3-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c5855fc6ace4cd768950816bde0256302fbe2290a4f6237e352095958286834 |
|
MD5 | 1e4bc4aa400674c561f63760d04b8d2b |
|
BLAKE2b-256 | 5f313abc17a150762f6b44cf8c11dae208087506b028082dc9f261903350e833 |
Hashes for yawinpty-0.4.3-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a38e20632eeafb13837e3dd77c3dc65d8b2ca534237c4e3d4b91f98c4f5a0298 |
|
MD5 | 2bdbf0669271607d2e4a64e8e025087b |
|
BLAKE2b-256 | f17f5fd1322933177c46d1dfbbdfd5aef63448a4c373df60085b8826c7a78b75 |
Hashes for yawinpty-0.4.3-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d259b926ebee9800bc85a161d1d1eb6aba217ee020cd025a949bff4c6bdccdc4 |
|
MD5 | 4202bf7b33388e5a358eae69bc9d449d |
|
BLAKE2b-256 | 93d5956902d8b0cfa95cebe20e1a5e1e4ef07f115519fc8a66264ae2c8fab1d2 |
Hashes for yawinpty-0.4.3-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c3e6889fc19632e4a780adfbe447ee45d689fe71faff311270c5777f6be4bd2 |
|
MD5 | 27e6db64f150cbfcd2c67fe0f1450a2d |
|
BLAKE2b-256 | 4ebdaf926e824fcc6efed36713e56478b90d62ca673b1e0203ec3d93bb0ada89 |
Hashes for yawinpty-0.4.3-cp34-cp34m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4ad5a00bbc2b16b739c19218a3059a7629d1dd5729cb7a00f6ffc573d2346a6 |
|
MD5 | 9055f0a360ae4124af121afc5fc5ce1c |
|
BLAKE2b-256 | 85d85e6d70117b349881a187db22228ddedecafe5229a0c5eb60b506045f2c97 |
Hashes for yawinpty-0.4.3-cp34-cp34m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f49551df2d5f41cec25eb306c328af7638ecc49a3685100bf01a36a1f491d313 |
|
MD5 | a5e814c71345b03b8b791ee5b9f52092 |
|
BLAKE2b-256 | 93c5a15e6353e671796017852b84b6d527e17d8efb12ac57e42b646595017fbf |
Hashes for yawinpty-0.4.3-cp27-cp27m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f203e4814fc7a14ab8d484511eb629c933678c652922f3641156a71f4cfb1fbd |
|
MD5 | fa1fa872c4a22937110f8a6fb3437d18 |
|
BLAKE2b-256 | 9ce20095c493126293aed1f17f0bcd90cccee7bd99e29d598077ed8a90d4d310 |
Hashes for yawinpty-0.4.3-cp27-cp27m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d03eab5e1844de2e7597c5f42e15414f0a19bcdee7013dc1f64f4442342f7bfa |
|
MD5 | 389813e1a8ec30926bdc74691385cd9f |
|
BLAKE2b-256 | df879602c683ca21f945a17e1a3a5d2d8a00934edda428340817dcf96cd8e647 |