pty

Python: when to use pty.fork() versus os.fork()

自古美人都是妖i 提交于 2019-12-03 16:16:50
问题 I'm uncertain whether to use pty.fork() or os.fork() when spawning external background processes from my app. (Such as chess engines) I want the spawned processes to die if the parent is killed, as with spawning apps in a terminal. What are the ups and downs between the two forks? 回答1: The child process created with os.fork() inherits stdin/stdout/stderr from parent process, while the child created with pty.fork() is connected to new pseudo terminal. You need the later when you write a

Ruby - Problems with Expect and Pty

旧巷老猫 提交于 2019-12-03 08:39:21
I'm trying to write a Ruby script that will ssh over to a server, run a given command, and fetch the output from it. Here's what I've got so far, mostly adapted from the Programming Ruby book: require 'pty' require 'expect' $expect_verbose = true PTY.spawn("ssh root@x.y") do |reader, writer, pid| reader.expect(/root@x.y's password:.*/) writer.puts("password") reader.expect(/.*/) writer.puts("ls -l") reader.expect(/.*/) answer = reader.gets puts "Answer = #{answer}" end Unfortunately all I'm getting back is this: Answer = .y's password: Any idea what I've done wrong and how to alleviate this?

Pseudoterminal master reads what it has just written

限于喜欢 提交于 2019-12-03 06:32:00
I'm working on a project that interfaces "virtual devices" (python processes) that use serial port connections with real devices that also use serial ports, and I'm using pseudoterminals to connect several(more than 2) of these serial-port communications processes (modeling serial devices) together, and I've hit a bit of a snag. I've got a python process that generates pseudoterminals, symlinks the slave end of the pty to a file (so the processes can create a pyserial object to the filename), while the master ends are kept by my pty generating process and read; when data comes in on one master

Errors installing pty.js (node) on OS X

主宰稳场 提交于 2019-12-03 06:18:22
问题 I have run into an unusal problem when trying to install pty.js using node: If I run npm install pty.js I receive this error: > node-gyp rebuild CXX(target) Release/obj.target/pty/src/unix/pty.o ../src/unix/pty.cc:487:10: error: use of undeclared identifier 'openpty' return openpty(amaster, aslave, name, (termios *)termp, (winsize *)winp); ^ ../src/unix/pty.cc:533:10: error: use of undeclared identifier 'forkpty' return forkpty(amaster, name, (termios *)termp, (winsize *)winp); ^ 2 errors

Python: when to use pty.fork() versus os.fork()

南楼画角 提交于 2019-12-03 05:28:31
I'm uncertain whether to use pty.fork() or os.fork() when spawning external background processes from my app. (Such as chess engines) I want the spawned processes to die if the parent is killed, as with spawning apps in a terminal. What are the ups and downs between the two forks? The child process created with os.fork() inherits stdin/stdout/stderr from parent process, while the child created with pty.fork() is connected to new pseudo terminal. You need the later when you write a program like xterm: pty.fork() in parent process returns a descriptor to control terminal of child process, so you

Detecting when a child process is waiting for input

爱⌒轻易说出口 提交于 2019-12-03 04:52:40
问题 I'm writing a Python program for running user-uploaded arbitrary (and thus, at the worst case, unsafe, erroneous and crashing) code on a Linux server. The security questions aside, my objective is to determine, if the code (that might be in any language, compiled or interpreted) writes the correct things to stdout , stderr and other files on given input fed into the program's stdin . After this, I need to display the results to the user. The current solution Currently, my solution is to spawn

Using subprocess with select and pty hangs when capturing output

血红的双手。 提交于 2019-12-03 04:40:27
问题 I'm trying to write a python program that is able to interact with other programs. That means sending stdin and receiving stdout data. I cannot use pexpect (although it definitely inspired some of the design). The process I'm using right now is this: Attach a pty to the subprocess's stdout Loop until the subprocess exits by checking subprocess.poll When there is data available in the stdout write that data immediately to the current stdout. Finish! I've been prototyping some code (below)

Can you fool isatty AND log stdout and stderr separately?

拥有回忆 提交于 2019-12-02 20:09:36
Problem So you want to log the stdout and stderr (separately) of a process or subprocess, without the output being different from what you'd see in the terminal if you weren't logging anything. Seems pretty simple no? Well unfortunately, it appears that it may not be possible to write a general solution for this problem, that works on any given process... Background Pipe redirection is one method to separate stdout and stderr, allowing you to log them individually. Unfortunately, if you change the stdout/err to a pipe, the process may detect the pipe is not a tty (because it has no width

Errors installing pty.js (node) on OS X

孤者浪人 提交于 2019-12-02 19:41:15
I have run into an unusal problem when trying to install pty.js using node: If I run npm install pty.js I receive this error: > node-gyp rebuild CXX(target) Release/obj.target/pty/src/unix/pty.o ../src/unix/pty.cc:487:10: error: use of undeclared identifier 'openpty' return openpty(amaster, aslave, name, (termios *)termp, (winsize *)winp); ^ ../src/unix/pty.cc:533:10: error: use of undeclared identifier 'forkpty' return forkpty(amaster, name, (termios *)termp, (winsize *)winp); ^ 2 errors generated. make: *** [Release/obj.target/pty/src/unix/pty.o] Error 1 gyp ERR! build error gyp ERR! stack

Detecting when a child process is waiting for input

眉间皱痕 提交于 2019-12-02 19:14:16
I'm writing a Python program for running user-uploaded arbitrary (and thus, at the worst case, unsafe, erroneous and crashing) code on a Linux server. The security questions aside, my objective is to determine, if the code (that might be in any language, compiled or interpreted) writes the correct things to stdout , stderr and other files on given input fed into the program's stdin . After this, I need to display the results to the user. The current solution Currently, my solution is to spawn the child process using subprocess.Popen(...) with file handles for the stdout , stderr and stdin .