Hacker News new | past | comments | ask | show | jobs | submit login
Daniel J. Bernstein's ptyget toolset (jdebp.uk)
113 points by todsacerdoti on April 21, 2022 | hide | past | favorite | 20 comments



>What's pty good for? I wrote the first versions of pty so that I could run pty nethack inside a script which would keep rerolling characters until I had both a ring of polymorph and a ring of polymorph control

Funny I wrote the same kind of start-scumming script against nethack.org using Python and pexpect.


I am curious with the use cases for something like this might be. I feel like it's very rare nowadays to encounter a CLI/TUI program that doesn't have a "non-interactive" alternative, either in a different tool or built into the application itself.

I know that pexpect can be used for testing such applications though. Is this meant to be for a similar use case? Or were "interactive-only" tools more common at one time in the past?


I sometimes want "nobuf" or something like it. I run some command that produces output promptly. Then I pipe it through grep or tee and the output doesn't show up as promptly, because it's switched from line buffering to block buffering. "nobuf" fixes this.

There's a command called "stdbuf" on Linux systems that accomplishes the same thing in a different way. It sets some magic environment variables [1], and that tells the subprocess to use line buffering, assuming it's using glibc [edit: or any dynamically-linked libc] and stdio. No pty actually required then.

stdbuf's manpage has an example:

       tail -f access.log | stdbuf -oL cut -d ' ' -f1 | uniq
       This will immediately display unique entries from access.log
[1] edit: just checked. It injects its own code via the LD_PRELOAD environment variable, and then controls that with other environment variables. LD_PRELOAD is gross but it works, I guess.


LD_PRELOAD is the greatest thing ever.


I think automating nethack is sufficient reason for this tool.


There's no wrong way to play, but savescumming makes it a different kind of game!

Sadly the AIs (nethackchallenge.com) are not yet good enough to show us what closer to optimal play looks like.


I typically play on public servers to avoid any save game temptations, or the reverse, removing terrifying bones infested with rogue pet vampires and cursed artifacts...

I'm disappointed that DJB didn't automate polypiling until he got what he wanted, rather than just rolling new characters until getting the desired combination of resources. At that point, I'd just say that save game editing and RNG grinding are comparable...

If you're reading this, DJB, thanks for all the awesome and weird tools! Perhaps you're not as widely attributed as you should be but I see your influences everywhere in modern unix.

(edited to change "fingerprints" to "influences" -- things like systemd or the later solaris init replacement are clearly a funhouse mirror re-imagning of daemontools and family -- but fingerprints implies that DJB touched these things which I'm pretty confident he didn't)


There are a bunch of aspects to optimal play in NetHack that are pretty unfun for humans to perform (but dramatically increase win rate). These things can all be programmed into an AI without too much trouble, some more fiddly than others:

* Always retrace your own steps when backtracking. Only walk on new tiles when it’s absolutely necessary for exploration. This greatly reduces your chances of stepping on unseen traps.

* Abuse shops to the max. Price ID everything you find. Sell every last bit of junk. Engage in credit cloning. Steal everything from shops.

* Abuse the protection racket. Max out on divine protection by spending all of the money from every shopkeeper’s pocket at the temple in minetown.

* Abuse alchemy to make large stacks of holy water and blessed potions of full healing. Increase your max HP to several hundred.

* Pudding farming. This one has thankfully been patched out.

* Polypiling. Polymorph lines of items on the floor. Try to get magic markers to write more scrolls of enchant armour.


not as consistent as the best humans yet, but they have won https://github.com/krajj7/BotHack


Bit of an edge use case but I had a backup server that the ssh would only take a password from interactive keyboard wouldn't accept the password argument for scp. Something like this could have fixed the issue, I ended up just going for a different provider that allowed ssh keys.


There is also sshpass, which allows non-interactive ssh password auth.

You can provide the password on the command line, or in an environment variable:

  sshpass -p 'PASSWORD' ssh user@host /bin/id
  SSHPASS=PASSWORD sshpass -e ssh user@host /bin/id
Not ideal, but if you're working with inflexible third parties who don't understand public keys, sometimes it's acceptable.

Storing secrets in environment variables is a common practice in many mostly-reasonable orgs.


OpenSSH also supports using a script to get the password if using the `SSH_ASKPASS` environment variable, and being invoked under a non-tty input e.g.

  { echo '#!/bin/sh' ; echo 'echo my_password' ; } > password.sh # don't do it like this :-p
  chmod +x password.sh

  SSH_ASKPASS=./password.sh DISPLAY= setsid ssh user@host /bin/id

In newer SSH versions `DISPLAY` is not required (but there is a new `SSH_ASKPASS_REQUIRE` environment variable), but in older (e.g. 8.x) versions, then it needs to be set as the default ssh-ask-password was an X11 command, and I believe the logic assumed that scenario.


IIRC I've used the expect command more than once for similar use cases.


The most common use-case I can think of (and one I've often wanted myself) is programs that only colorize when writing to a terminal, and you want to save the output but still keep the colors.


Does gpg have non-interactive mode yet? I vaguely recall automating pass phrase entry being borderline impossible.


It has for a long time but it is still not ideal for editing subkeys and what not.


I've been doing non-interactive gpg without an issue since 2014.


`empty` is a similar tool.

Source (clone of the original SF repo): https://github.com/ierton/empty

Man page: http://manpages.ubuntu.com/manpages/trusty/man1/empty.1.html


> In the 1990s Daniel J. Bernstein wrote a pty package, in order to cheat at nethack.

Now I want to know more. I assume he was automating input to the game? But how was he analyzing state?


It's pretty easy to inspect the nethack state since it's all text. When I wrote a script to reroll nethack characters in the past, I just opened the inventory and used "grep" to search for desired items.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: