Comments (10)
Hi @Robatronic, thanks for reaching out! I have two questions regarding your use-case of pywinpty:
- Have you tried to use the library in a synchronous fashion? Without using async primitives?
- Do you know which backend is being used? Right now
ConPTY
is using VT100 by default: https://github.com/andfoy/winpty-rs/blob/3d5a3a8604be35ad0ce8e37b23dd5e7ab914697e/src/pty/conpty/pty_impl.rs#L126, in which case is better to use theWinPTY
backend
from pywinpty.
- I'm working on building one presently, I'll let you know how that goes. :)
- I have tried both ConPTY and WinPTY with the same results.
from pywinpty.
Here's what I wrote:
import logging
logging.basicConfig(level=logging.DEBUG)
from winpty import PtyProcess as PtyProcessUnicode, Backend
import time
import codecs
import socketserver
pty = None
OUTPUT_CACHE = b''
class ptyTCPHandler(socketserver.BaseRequestHandler):
"""
The request handler class for our server.
It is instantiated once per connection to the server, and must
override the handle() method to implement communication to the
client.
"""
def setup(self):
super().setup()
# Add to client list
print(f"Adding {self.client_address} to client list")
clients.append(self)
return(0)
def handle(self):
global OUTPUT_CACHE
# self.request is the TCP socket connected to the client
# self.request.sendall("Hello there!!".encode())
self.request.sendall(OUTPUT_CACHE)
while True:
self.data = self.request.recv(1024)
logging.info(f"TCP handler recvd: {self.data}")
pty.write(self.data.decode())
try:
ch = pty.read(65536)
OUTPUT_CACHE += ch.encode()
for client in clients:
print(f"Writing {ch.encode()} to {client.client_address}")
client.request.sendall(ch.encode())
except Exception as e:
print(f"#### EXCEPTION: ptyTCPHandler: {e}")
break
def finish(self):
print(f"Removing {self.client_address} from client list..")
clients.remove(self)
if __name__ == "__main__":
subproc_name = "cmd.exe"
# subproc = "python.exe"
pty = PtyProcessUnicode.spawn(subproc_name, backend=Backend.WinPTY)
# pty = PtyProcessUnicode.spawn(subproc_name, backend=Backend.ConPTY)
pty.decoder = codecs.getincrementaldecoder('utf-8')(errors='replace')
pty.name = subproc_name
print(f"pty size: (rows, columns): {pty.getwinsize()}")
# Get first few lines from process startup
time.sleep(0.5)
OUTPUT_CACHE += pty.read(65536).encode()
# Start socket server
HOST, PORT = "localhost", 11000
# Create the server, binding to localhost on port 9999
with socketserver.TCPServer((HOST, PORT), ptyTCPHandler) as server:
# Activate the server; this will keep running until you
# interrupt the program with Ctrl-C
print(f"TCP Server running on {HOST}:{PORT}")
server.serve_forever()
exit(0)
from pywinpty.
This is the output on connecting:
0;C:\Windows\System32\cmd.exeMicrosoft Windows [Version 10.0.18363.1556][9C
(c) 2019 Microsoft Corporation. All rights reserved.
[52C
D:\sandbox\epics\pyProcServ\area_51>[16C
from pywinpty.
...then, after hitting enter and typing in dir....
D:\sandbox\epics\pyProcServ\area_51>ddirir
Volume in drive D is DATA[35C
Volume Serial Number is DCBD-282A[27C
[61C
Directory of D:\sandbox\epics\pyProcServ\area_51[12C
[61C
2022-08-17 04:51 PM <DIR> .[21C
2022-08-17 04:51 PM <DIR> ..[20C
2021-12-09 06:06 PM 943 asyncio_echo_client.py
2021-12-09 06:05 PM 785 asyncio_echo_server.py
2021-12-10 12:41 AM 4,202 asyncio_subprocess.py
2021-12-18 05:26 AM 1,389 asyncio_testing.py
2022-08-10 03:58 PM 1,001 book_samples.py
2022-01-13 05:50 PM 533 common_demo_stuff.py
2022-08-12 10:58 AM 3,380 constants.py[10C
2022-01-11 01:32 AM 2,260 create_task.py
2021-12-09 10:24 PM 18 dir.bat[15C
2021-12-24 04:35 PM 854 echoProc.py[11C
2021-12-09 05:33 PM 673 echo_server.py
0;C:\Windows\System32\cmd.exe - dir861 junk.txt[14C
2022-08-10 03:53 PM 158 listin
g_13_11.py[25C
2022-08-10 04:16 PM 269 listing_13_13.py[25C
2022-08-10 04:28 PM 1,994 listing_13_14.py[25C
2022-08-09 09:04 PM 1,275 localShell.py[28C
2022-01-11 02:37 AM 892 misc.py[34C
2021-12-09 03:52 PM 2,515 pipe_client.py[27C
2021-12-09 03:51 PM 2,431 pipe_server.py[27C
2022-01-16 04:45 PM 1,200 prime_numbers.py[25C
2022-08-09 09:25 PM 5,591 ptyprocess.py[28C
2022-08-17 04:51 PM 16,769 pty_testing.py[27C
2021-12-20 04:29 PM 6,675 pynCA.py[33C
2021-12-18 10:14 AM 0 pynCA_helpers.py[25C
2022-03-24 03:52 PM 23 run_pty.bat[30C
2022-08-17 03:34 PM 38,758 server.log[31C
2022-08-17 02:57 PM 25,438 simple_server.py[25C
2021-12-09 03:49 PM 3,686 socket_stream_redirect.py[16C
2021-12-21 01:59 PM 3,963 stream_testing.py[24C
2022-08-10 04:41 PM 8,423 sys_calls.py[29C
2022-01-13 06:00 PM <DIR> templates[32C
2021-12-09 03:52 PM 635 test-socket_stream_redirect.py[11C
2022-01-27 08:09 PM 11,979 test_subprocess.py[23C
2022-01-13 08:52 PM 2,498 web_term.py[30C
2022-08-10 05:12 PM 4,538 winpsuedoterm.py[25C
2022-08-15 10:07 AM <DIR> __pycache__[30C
34 File(s) 166,609 bytes[35C
4 Dir(s) 1,703,480,389,632 bytes free[27C
0;C:\Windows\System32\cmd.exe
D:\sandbox\epics\pyProcServ\area_51>[44C
from pywinpty.
Telnet settings:
Escape Character is 'CTRL+]'
Will auth(NTLM Authentication)
Local echo off
New line mode - Causes return key to send CR & LF
Current mode: Console
Will term type
Preferred term type is ANSI
from pywinpty.
Looking at it, I'm starting to wonder if some of the escape codes aren't being sent as an atomic unit.....
from pywinpty.
The terminado project is very slick.
I'm trying to do similar with regular sockets rather than websockets.....
from pywinpty.
Does terminado outputs the program correctly?
from pywinpty.
It does
I first found Terminado in Jupyterlab and dug in to find it uses pyWinPty.
I have another experiment I want to do to try and track down where the issue is.
from pywinpty.
Related Issues (20)
- Write output corruption when spawning pwsh HOT 4
- Release v2.0.2
- Release v2.0.3
- ConPTY is not fully working in CI HOT 4
- Build failure on windows py3.6 HOT 1
- Release v2.0.4
- Release v2.0.5
- Async read?
- Release v2.0.6
- Release v2.0.7
- Release v2.0.8
- Failed to install with python 3.11 HOT 2
- 'Pty is closed.' BUG
- Release v2.0.10
- ssh connection establish failed.
- How do I get the same functionality as pty.spawn? HOT 6
- [Question] Messed up display buffer after resize? HOT 2
- Question: Does `PTY.write()` take in unicode string or bytes?
- PtyProcess.spawn cwd parameter not working HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pywinpty.