pty

Why does OpenSSH RequestTTY cause stderr redirected to stdout?

两盒软妹~` 提交于 2019-12-05 01:18:10
问题 When running the same ssh command with -T and -t, any stderr output arrives on stderr vs. stdout, respectively. No pty allocated: ssh -T user@host "echo >&2 foo" 1>/tmp/out 2>/tmp/err Output is written to /tmp/err . With pty allocation: ssh -t user@host "echo >&2 foo" 1>/tmp/out 2>/tmp/err Output is now written to /tmp/out . I somewhat understand that with pty a full pseudo screen is simulated and that the output is in raw mode. The output sent to the screen then are sent via stdout back to

usage of pseudo terminal — C

≯℡__Kan透↙ 提交于 2019-12-04 21:02:33
I created a pThread with a specific session number. If the pThread is spawned I try to get another process running the pseudo terminal launched using openpty . Here is some part of the code: if (openpty(&(numa_pst[session][0]),&(numa_pst[session][1]), NULL, NULL, NULL) != 0) { int err_code = errno; sprintf (line_temp, "*** ERROR: numa openpty failed with:\n%s\n", strerror(err_code)); } session = 0; int* pi = calloc(sizeof(int), 1); *pi = session; if (pthread_create(&system_wideThread[session], 0, system_wider, (void*)pi)) { int err_code = errno; sprintf (line_temp, "*** ERROR: System-wide

How can I interact with another program in Python?

微笑、不失礼 提交于 2019-12-04 14:17:09
问题 I want to write a Python script that runs another program, reading the output of the other program and manipulating it. The problem is that this program prompts for a password, and I cannot figure out how to supply it automatically. (For the purposes of this script, it really does not matter if the password is stored in plain-text in the script itself.) What I want to do is something like: os.system('echo someinput | /var/local/bin/someprogram') Which results in someprogram giving me the

Ruby - Problems with Expect and Pty

岁酱吖の 提交于 2019-12-04 13:46:51
问题 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

Pseudoterminal master reads what it has just written

自古美人都是妖i 提交于 2019-12-04 10:41:36
问题 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),

Executing string sent from one terminal in another in Linux pseudo-terminal

我与影子孤独终老i 提交于 2019-12-04 06:57:42
问题 Lets say I have one terminal where the output of "tty" is "/dev/pts/2" From another terminal, I want to send a command to the first terminal and execute it. Using: echo "ls" > "/dev/pts/2" only prints "ls" in the first terminal Is there a way to execute the string? 回答1: No; terminals don't execute commands. They're just channels for data. You can sort of run a command and attach it to another terminal like this, though: ls </dev/pts/2 >/dev/pts/2 2>/dev/pts/2 It won't behave exactly like you

Simplest way to get a PTY in Linux C++

天大地大妈咪最大 提交于 2019-12-04 04:16:59
问题 I am programming something that needs an interface to Bash. At first I thought I could just use popen or QProcess. ( I'm using QT C++ ) They work fine but I can't get them to run Bash in a tty, which you need if you are going to use anything like sudo, which requires a tty/pty to accept a password. I found some things like forkpty(), openpty(), etc. in the GNU Standard C libraries, but could not figure out how to use them or find any good examples, even after reading their corresponding

PTY gem not found

不想你离开。 提交于 2019-12-04 04:04:39
问题 I have Ruby 1.9.3 installed on windows. When I try to require the gem the console outputs that the gem was not found: require 'pty' Which outputs: 'require': cannot load such file -- pty <LoadError> Also I tried: gem install pty And got this output: Could not find a valid gem 'pty' in any repository How do I fix this? 回答1: As far as I know, there is no PTY module implementation for Windows as they don't have pseudo-terminal capabilities. 回答2: You can try gem install rubysl-pty if target ruby

Troubleshooting OSError: out of pty devices

十年热恋 提交于 2019-12-04 03:28:19
问题 From time to time I'm getting an OSError exception with the message 'out of pty devices' when calling pty.openpty() (it's happening when a bunch of instances of my scripts run concurrently). What is the limit that I'm hitting? How can I get around this? CentOS 5.6, Python 2.4 回答1: In my Ubuntu Linux, the max number of open ptys is given by: cat /proc/sys/kernel/pty/max This value is configurable in: /etc/sysctl.conf All this info, and much more can be found in: man pty 回答2: Same issue is

Python os.forkpty why can't I make it work

佐手、 提交于 2019-12-03 20:54:25
import pty import os import sys import time pid, fd = os.forkpty() if pid == 0: # Slave os.execlp("su","su","MYUSERNAME","-c","id") # Master print os.read(fd, 1000) os.write(fd,"MYPASSWORD\n") time.sleep(1) print os.read(fd, 1000) os.waitpid(pid,0) print "Why have I not seen any output from id?" You are sleeping for too long. Your best bet is to start reading as soon as you can one byte at a time. #!/usr/bin/env python import os import sys pid, fd = os.forkpty() if pid == 0: # child os.execlp("ssh","ssh","hostname","uname") else: # parent print os.read(fd, 1000) os.write(fd,"password\n") c =