tty

Golang reading from stdin, how to detect special keys (enter, backspace… etc)

帅比萌擦擦* 提交于 2020-01-10 20:07:10
问题 I have the following program that reads user input from stdin: var input string = "" exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run() exec.Command("stty", "-F", "/dev/tty", "-echo").Run() var b []byte = make([]byte, 1) for { input += string(b) } I want to place some kind of condition inside the for loop so that i can "break" when the user presses "enter" (for example) or remove one char from a string when the user presses (backspace). However, i can't figure out what the

How i can read tty file with timeout?

牧云@^-^@ 提交于 2020-01-03 13:08:37
问题 I have tty device in /dev , where I send AT commands. I want to read line by line and stop reading file after timeout. 回答1: You can use the program stty to configure the tty device. To see the settings for terminal /dev/ttyS0, try stty -a -F /dev/ttyS0 The default settings regarding timeout are min = 1; time = 0 , which means that the reading program will read until at least one character has been read and there is no timeout. Using e.g. stty -F /dev/ttyS0 min 0 time 10 the reading program (e

kubectl attach: Unable to use a TTY - container es-node did not allocate one

旧巷老猫 提交于 2020-01-01 08:19:09
问题 I am trying to attach to a running container in Kubernetes, however I get the error message below. >kubectl attach -it es-client-2756725635-4rk43 -c es-node Unable to use a TTY - container es-node did not allocate one If you don't see a command prompt, try pressing enter. How do I enable a TTY in my container yaml? 回答1: In order to have proper TTY and stdin when doing attach: kubectl attach -it POD -c CONTAINER The container must be configured with tty: true and stdin: true . By default both

ksh: how to probe stdin?

非 Y 不嫁゛ 提交于 2020-01-01 06:15:31
问题 I want my ksh script to have different behaviors depending on whether there is something incoming through stdin or not: (1) cat file.txt | ./script.ksh (then do "cat <&0 >./tmp.dat" and process tmp.dat) vs. (2) ./script.ksh (then process $1 which must be a readable regular file) Checking for stdin to see if it is a terminal[ -t 0 ] is not helpful, because my script is called from an other script. Doing "cat <&0 >./tmp.dat" to check tmp.dat's size hangs up waiting for an EOF from stdin if

Read and Write from serial port under Ubuntu for USB scale

本小妞迷上赌 提交于 2019-12-24 21:25:10
问题 I have a digital scale connected via USB to my Ubuntu laptop and I would like to read the measurements from it. The serial protocol is very simple (9600,8N1, ttyUSB0) and I'm able to correctly read the measurements by using putty (VT100+) from terminal. The scale needs to receive the command "READ<CR><LF>" in order to send the measurement. Each measurement has this format: 01ST,GS, 2.5,kg<CR><LF> if, for example, I'm measuring a 2.5Kg load. Now, I'm trying to send the READ command from a C

how to redirect the output of serial console (e.g. /dev/ttyS0) to a buffer or file

你离开我真会死。 提交于 2019-12-24 12:19:03
问题 Is it possible to pipe serial console output to a file or a buffer or some virtual or pseudo device (in /dev)? The Kernel command line has in startup at this point "console=null,115200". (Normally it has "console=ttyS0,115200" - my requirement is: if "console=null,115200", should the output go to some other place than ttyS0, e.g. a virtual or pseudo device or to a file/buffer) Maybe somebody know if there is good solution available? Thanks a lot in advance! 回答1: There are two ways that I am

How to read-write character devices (like /dev/ttyS0) in Android

北城余情 提交于 2019-12-24 11:30:25
问题 I have little knowledge of Java and Android. What I am trying to do is to open /dev/ttyS0 in an Android App which should talk to the serial line, but I am getting lost. My device is rooted, and from a command line I can "echo ...>/dev/ttyS0" and also read from it, but I get lost trying to do that in Java. For start, I can not find a method to open a file in simple read-write mode, without coping with buffers and other intricacies (clearly, I want unbuffered I/O). I searched the Internet, but

winpty consumes git bash shell

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 01:24:47
问题 I have Windows 10. I can't enable Hyper V, so I'm using Docker Toolbox. My terminal of choice is git bash, which is a Msys2 terminal. Normally, everything works fine, except when I need an interactive terminal. For instance, docker login artifactory.mycompany.com gives: Error: Cannot perform an interactive login from a non TTY device When I try instead winpty docker login artifactory.mycompany.com nothing happens, but my console input and output is completely consumed (nothing is displayed

I can't sys.stdout.seek

淺唱寂寞╮ 提交于 2019-12-24 00:42:31
问题 From what I know, sys.stdout is a file that represents the stdout of a terminal. However, when I try to use sys.stdout.seek , whatever parameters I give it, it throws an error: IOError: [Errno 29] Illegal seek What's going on? Is it the fact that I'm using the TTY itself and not a virtual terminal like xterm? How can I resolve this? 回答1: When stdout is a TTY it's a character device and it's not seekable, you cannot seek in a TTY. Same for tell , it's not implemented: >>> sys.stdout.tell()

docker-compose exec python the input device is not a TTY in AWS EC2 UserData

好久不见. 提交于 2019-12-23 07:47:29
问题 I am using EC2 UserData to bootstrap the instance. TRacking log of bootstrap execution /var/log/cloud-init-output.log , I found that the script was stopped at : + docker-compose exec web python /var/www/flask/app/db_fixtures.py the input device is not a TTY It seems like this command it's running in interactive mode, but why ? and how to force noninteractive mode for this command (docker-compose exec) ? 回答1: Citing from the docker-compose exec docs: Commands are by default allocating a TTY,