pty

Why can I not read from stdin in this forked process?

对着背影说爱祢 提交于 2019-12-10 23:36:40
问题 The following code prints nothing, but it should print out "a" repeatedly. The forked process blocks on the os.read(0, 1). The parent process is indeed writing to the stdin_master, but stdin_slave receives nothing. Any ideas? import os import pty import resource import select import signal import time stdin_master, stdin_slave = pty.openpty() stdout_master, stdout_slave = pty.openpty() stderr_master, stderr_slave = pty.openpty() pid = os.fork() # child process if pid == 0: os.setsid() os

To run sudo commands on a ec2 instance

只谈情不闲聊 提交于 2019-12-10 14:50:09
问题 I cannot run "sudo su" on my ec2 client , I ssh into the client through a java program and run the command through a program. I can run commands like "ls" and "ifconfig" though. I get an error saying "sudo: sorry, you must have a tty to run sudo". How can I run the command, I am using Jsch for ssh to my ec2 instance. 回答1: You can do "sudo" without pseudo-tty with JSch, by using the -S option to sudo . See the Sudo.java on the JSch website for a complete example. (I'm the author of JSch.) 回答2:

How to send Ctrl-C control character or terminal hangup message to child process?

天涯浪子 提交于 2019-12-09 09:22:56
问题 I have a child process which runs in a pseudo terminal. The parent process does not run as root, but the child process does, through su or sudo. Because of this it is not possible to send a signal to the child process to force it to exit. I want to force it to exit by one of these means: emulating a Ctrl-C. emulating a terminal hangup. How do I do either of these? I already have a pty master fd, and I've tried something like this: write(master, &termios.c_cc[VINTR], 1) but it doesn't do

Ruby on Linux PTY goes away without EOF, raises Errno::EIO

烈酒焚心 提交于 2019-12-08 23:40:44
问题 I'm writing some code which takes a file, passes that file to one of several binaries for processing, and monitors the conversion process for errors. I've written and tested the following routine on OSX but linux fails for reasons about which I'm not clear. #run the command, capture the output so it doesn't display PTY.spawn(command) {|r,w,pid| until r.eof? do ##mark puts r.readline end } The command that runs varies quite a lot and the code at the ##mark has been simplified into a local echo

ssh remote server login script

醉酒当歌 提交于 2019-12-08 04:53:06
问题 Currently I am trying to write a ruby script to logging-in SSH Remote Server using "pty" & "expect" ruby library. and also try to create new rails app inside the remote system using that script. Anyone can tell me. how logging-in to remote server using the ruby library ? 回答1: You should look at some of the examples for Net::SSH , it basically opens a connection and gives you a block to execute whatever command you like, e.g.: #!/usr/bin/env ruby require 'rubygems' require 'net/ssh' HOST =

Send command and exit using python pty pseudo terminal process

人盡茶涼 提交于 2019-12-07 17:32:06
问题 Using python pty module, i want to send some commands to the terminal emulator, using a function as stdin (as pty module wants), and then force quitting. I thought about something like import pty cmnds = ['exit\n', 'ls -al\n'] # Command to send. I try exiting as last command, but it doesn't works. def r(fd): if cmnds: cmnds.pop() # It seems is not executing sent commands ('ls -al\n') else: # Can i quit here? Can i return EOF? pass pty.spawn('/bin/sh', r) Thank you 回答1: Firstly, the pty module

How to switch terminal to new child process of process launched with NSTask?

别来无恙 提交于 2019-12-07 09:53:55
I made a pseudo terminal with method described here: http://lists.apple.com/archives/student-dev/2005/Mar/msg00019.html The terminal itself worked well. Anyway the problem is terminal cannot being switched to child process. For an example, I launched bash with NSTask , and if I execute ftp within the bash , it stops automatically. ftp ftp ftp> [1]+ Stopped ftp bash-3.2$ And if I try to continue the ftp with fg , it terminates quietly. (I checked this with Activity Monitor ) fg fg ftp bash-3.2$ fg fg bash: fg: current: no such job bash-3.2$ I think it needs some more infrastructure (which

usage of pseudo terminal — C

白昼怎懂夜的黑 提交于 2019-12-06 15:00:06
问题 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]

forkpty - socket

随声附和 提交于 2019-12-06 06:13:16
问题 I'm trying to develop a simple "telnet/server" daemon which have to run a program on a new socket connection. This part working fine. But I have to associate my new process to a pty, because this process have some terminal capabilities (like a readline). The code I've developped is (where socketfd is the new socket file descriptor for the new input connection) : int masterfd, pid; const char *prgName = "..."; char *arguments[10] = ....; if ((pid = forkpty(&masterfd, NULL, NULL, NULL)) < 0)

Send command and exit using python pty pseudo terminal process

一曲冷凌霜 提交于 2019-12-06 03:37:05
Using python pty module, i want to send some commands to the terminal emulator, using a function as stdin (as pty module wants), and then force quitting. I thought about something like import pty cmnds = ['exit\n', 'ls -al\n'] # Command to send. I try exiting as last command, but it doesn't works. def r(fd): if cmnds: cmnds.pop() # It seems is not executing sent commands ('ls -al\n') else: # Can i quit here? Can i return EOF? pass pty.spawn('/bin/sh', r) Thank you Firstly, the pty module does not allow you to communicate with the terminal emulator Python is running in. Instead, it allows