0

If I do cat > filename.ext and then type in a bunch of text that text will (1) be echo'd onto the screen as I type it in and (2) appear in filename.ext.

That's okay if I'm doing that for text files but it's more problematic if I'm doing it for binary files because strange things can happen as discussed in https://www.chiark.greenend.org.uk/~sgtatham/putty/faq.html#faq-puttyputty .

So any ideas how I might be able to make it so that keys that I type aren't echo'd back to the screen?

neubert
  • 175
  • 1
  • 1
  • 7
  • 1
    I'm confused, are you typing input or `cat`ing binary files? – jesse_b Feb 08 '20 at 16:40
  • If you create a file by using cat and typing input it wont be a binary file so I just don't see any issue here – jesse_b Feb 08 '20 at 16:46
  • See https://unix.stackexchange.com/q/210628/117549 – Jeff Schaller Feb 08 '20 at 16:51
  • @jesse_b - I'm using an SSH library to dump the contents of a binary file into stdin. eg. `$ssh->exec('cat > filename.txt'); $ssh->write(file_get_contents('filename.ext'))`. ie. I'm not using iTerm nor am I using PuTTY (both of which would presumably limit stdin to characters on the keyboard) but rather, I'm using an SSH library, which affords me more fine tuned control over what's being sent. – neubert Feb 08 '20 at 17:08
  • Your question should really mention that you are writing an incredibly fragile file transfer mechanism, where the recipient end is `cat` with the terminal in canonical mode. There are reasons that ZMODEM and others worked as they did. – JdeBP Feb 09 '20 at 13:13

1 Answers1

1

Yes, turn echo off in the ttys settings. From the shell you can do that with stty -echo:

(g=$(stty -g); stty -echo; cat > outfile; stty "$g")
<type blindly, finish by Enter, Control-D>
  • When I do `ssh localhost '(g=$(stty -g); stty -echo; cat > outfile2; stty "$g")'` I get a `stty: 'standard input': Inappropriate ioctl for device` error. Any idea what's up with that? – neubert Feb 13 '20 at 13:43
  • 1
    use the `-t` option to force ssh to allocate a pseudo-tty; `ssh` will only do that by default when it's used with no `command` argument. –  Feb 13 '20 at 19:24
  • 1
    you may need TWO `-t` (`ssh -tt`) if the stdin of the ssh command is not a tty. –  Feb 13 '20 at 19:27