-1

A friend of mine wrote python code on a Mac, and now I'm trying to get it to work on a windows laptop.

This line in particular is being annoying:

os.system("stty echo")

Anyone know a windows equivalent? I've already replaced tty with msvcrt, but I am completely stuck on this.

Fraidy cat
  • 21
  • 2
  • You should explain what the command does: `stty echo` since many users do not know what it does. – eyllanesc Oct 10 '18 at 02:21
  • 1
    Can your friend tell you what the purpose, value, need of that particular snippet is? And then see if something comparable exists? Also, it may be better to use `subprocess` when interacting with the os than `os.system` – user9074332 Oct 10 '18 at 02:31
  • Look for `echo on` on windows? – atline Oct 10 '18 at 04:30
  • 1
    Was the console's [`ENABLE_ECHO_INPUT`](https://learn.microsoft.com/en-us/windows/console/setconsolemode) mode disabled at some point? If not, you should be able to omit this line. Otherwise you'll need ctypes or PyWin32 to call `GetConsoleMode` and `SetConsoleMode`. – Eryk Sun Oct 10 '18 at 15:25
  • @lagom, the CMD shell's `echo` command has nothing to do with the console echoing input. The closest the Windows command line has to stty is mode.com, but it only controls a small subset of console modes for compatibility with old batch scripts. – Eryk Sun Oct 10 '18 at 15:26
  • Explanation of `stty echo`: [What does "stty raw -echo" do on OS X](https://stackoverflow.com/a/22837780/411282) – Joshua Goldberg Jun 04 '21 at 17:45

1 Answers1

1

Ended up finding a solution a couple hours later. I added a function to the code that checked if it was a unix of windows computer, and then used msvcrt when needed as a replacement.

I believe I used the code from here to fix the program: http://code.activestate.com/recipes/134892-getch-like-unbuffered-character-reading-from-stdin/

Fraidy cat
  • 21
  • 2