tty

How do I detect if stdout is connected to a tty in Perl?

余生长醉 提交于 2019-11-27 23:43:28
问题 I'm looking for the Perl equivalent to this Python code: from sys import stdout if stdout.isatty(): print "yes" else: print "no" 回答1: Use the -t filetest operator. print -t STDOUT ? "Yes\n" : "No\n" Note that in Perl, STDOUT can be tied (essentially an overcomplicated overloaded object) so output to STDOUT may still reach a TTY even if its not directly attached to one. 回答2: Use IO::interactive if you require STDOUT to actually be connected to the terminal, and not just being redirected to

How to create a pseudo-tty for reading output and writing to input

こ雲淡風輕ζ 提交于 2019-11-27 18:20:13
问题 I am using fork() and execvp() to spawn a process that must believe it is connected to an interactive terminal for it to function properly. Once spawned, I want to capture all the output from the process, as well as be able to send input to the process. I suspect psuedo-ttys may help here. Does anyone have a snippet on how to do this? 回答1: You want to call forkpty(). From the man page: #include <pty.h> /* for openpty and forkpty */ pid_t forkpty(int *amaster, char *name, struct termios *termp

MacOS: what's the difference between /dev/tty.* and /dev/cu.*?

丶灬走出姿态 提交于 2019-11-27 17:29:05
Each serial device shows up twice in /dev , once as a tty.* and once as a cu.* . What is the cu.* device? How does it differ from the tty.* device? mh@maru ~ --> ls -l /dev/*.usbmodem621 crw-rw-rw- 1 root wheel 11, 5 Dec 25 18:00 /dev/cu.usbmodem621 crw-rw-rw- 1 root wheel 11, 4 Dec 25 18:00 /dev/tty.usbmodem621 http://lists.berlios.de/pipermail/gpsd-dev/2005-April/001288.html : The idea is to supplement software in sharing a line between incoming and outgoing calls. The callin device (typically /dev/tty*) is used for incoming traffic. Any process trying to open it blocks within the open()

Vagrant is attempting to interface with the UI in a way that requires a TTY

最后都变了- 提交于 2019-11-27 17:22:29
问题 Problem: vagrant up fails with the error below. I am running vagrant on Windows 7 and the base box is Ubuntu )( files.vagrantup.com/precise32.box ). how can it be fixed? vagrant.bat up Bringing machine 'default' up with 'virtualbox' provider... [default] Clearing any previously set forwarded ports... [default] Clearing any previously set network interfaces... [default] Available bridged network interfaces: 1) Intel(R) PRO/1000 EB Network Connection with I/O Acceleration 2) Intel(R) PRO/1000

Confused about Docker -t option to Allocate a pseudo-TTY

梦想的初衷 提交于 2019-11-27 16:47:33
What exactly does this option do? I've been reading a lot on TTY and am still confused. I played around with not having the -t and just -i and it seems like programs that expect user input throw an error without the -t . Why is it important for pseudo-TTY to be enabled? The "-t" option goes to how Unix/Linux handles terminal access. In the past, a terminal was a hardline connection, later a modem based connection. These had physical device drivers (they were real pieces of equipment). Once generalized networks came into use, a pseudo-terminal driver was developed. This is because it creates a

What do pty and tty mean?

断了今生、忘了曾经 提交于 2019-11-27 09:57:59
I noticed there are many mentions of pty and tty in some opensource projects, could someone can tell me what do they mean and what is the difference between them? Thanks! Charlie Martin "tty" originally meant "teletype" and "pty" means "pseudo-teletype". In UNIX, /dev/tty* is any device that acts like a "teletype", ie, a terminal. (Called teletype because that's what we had for terminals in those benighted days.) A pty is a pseudotty, a device entry that acts like a terminal to the process reading and writing there, but is managed by something else. They first appeared (as I recall) for X

How to write data to existing process's STDIN from external process?

久未见 提交于 2019-11-27 07:50:31
I'm seeking for ways to write data to the existing process's STDIN from external processes, and found similar question How do you stream data into the STDIN of a program from different local/remote processes in Python? in stackoverlow. In that thread, @Michael says that we can get file descriptors of existing process in path like below, and permitted to write data into them on Linux. /proc/$PID/fd/ So, I've created a simple script listed below to test writing data to the script's STDIN (and TTY ) from external process. #!/usr/bin/env python import os, sys def get_ttyname(): for f in sys.stdin,

How do *nix pseudo-terminals work ? What's the master/slave channel?

北战南征 提交于 2019-11-27 07:06:41
I want to write a simple, dumb, X terminal emulator in C on a Linux system. At first, I just thought I would have to popen a shell and display its output. I checked xterm and rxvt code, and it looks a bit more complicated. First, I have to open a pseudo-terminal with openpty. So I look at the man page and see that openpty fills 2 file descriptors, the master and the slave. Both xterm and rxvt code are messy because of the system-dependent-ness of those specials files. I understand the termios stuff : it's just a bunch of information about the escape code of the terminal. What I really don't

Piping data to Linux program which expects a TTY (terminal)

谁说胖子不能爱 提交于 2019-11-27 04:24:19
I have a program in Linux which refuses to run if its stdin/stdout is not a TTY (terminal device). Is there an easy-to-use tool which will create a PTY, start the program with the newly created TTY, and copy all data over stdin/stdout? The use case is not interactive, but scripting. I'm looking for the most lightweight solution, preferably not creating TCP connections, and not requiring too many other tools and libraries to be installed. Ignacio Vazquez-Abrams unbuffer , part of expect ( sudo apt-get install expect-dev on Ubuntu Lucid), can fool a program into thinking it's connected to a TTY.

Using netcat/cat in a background shell script (How to avoid Stopped (tty input)? )

自作多情 提交于 2019-11-27 02:52:28
问题 Abstract: How to run an interactive task in background? Details: I am trying to run this simple script under ash shell (Busybox) as a background task. myscript.sh& However the script stops immediately... [1]+ Stopped (tty input) myscript.sh The myscript.sh contents... (only the relvant part, other then that I trap SIGINT, SIGHUP etc) #!/bin/sh catpid=0 START_COPY() { cat /dev/charfile > /path/outfile & catpid = $! } STOP_COPY() { kill catpid } netcat SOME_IP PORT | while read EVENT do case