v1
This commit is contained in:
commit
8d4915543e
132 files changed
+20628
No files matched your search
@@ -0,0 +1,32 @@
|
||||
"""Drive `netssh configure` in huh's accessible mode (TERM=dumb): one answer
|
||||
per prompt, sent after a short pause so each form reads its own line."""
|
||||
import os
|
||||
import pty
|
||||
import select
|
||||
import sys
|
||||
import time
|
||||
|
||||
answers = sys.argv[1:]
|
||||
pid, fd = pty.fork()
|
||||
if pid == 0:
|
||||
os.execvpe("netssh", ["netssh", "configure"], dict(os.environ, TERM="dumb"))
|
||||
out = b""
|
||||
|
||||
|
||||
def drain(seconds):
|
||||
global out
|
||||
end = time.time() + seconds
|
||||
while time.time() < end:
|
||||
ready, _, _ = select.select([fd], [], [], 0.05)
|
||||
if ready:
|
||||
try:
|
||||
out += os.read(fd, 4096)
|
||||
except OSError:
|
||||
return
|
||||
|
||||
|
||||
for answer in answers:
|
||||
drain(0.5)
|
||||
os.write(fd, (answer + "\n").encode())
|
||||
drain(2)
|
||||
sys.stdout.write(out.decode(errors="replace"))
|
||||
Reference in new issue
Block a user