0

I am trying to install a few programs with Homebrew as a Python subprocess.

My code looks like this:

from subprocess import call
call(f"brew cask install {brew_command} --force", shell=True)

Everything works fine but I can't find how to pass my password to this process.

Acorn
  • 24,970
  • 5
  • 40
  • 69
  • Not sure, but I think you can provide the password just by writing it in the `stdin` stream of the subprocess – orlevii Sep 20 '20 at 08:32
  • If it's running sudo, passing to stdin won't work as the prompt is going direct to the TTY. – Charles Duffy Sep 20 '20 at 09:03
  • Does this answer your question? [Use subprocess to send a password](https://stackoverflow.com/questions/2387731/use-subprocess-to-send-a-password) – flaxel Sep 20 '20 at 09:06
  • 1
    @Victor, btw, from a security perspective, be aware that this lets someone run any command they want, not just `brew install` commands. If someone tells your script written with this code to install a package named ` – Charles Duffy Sep 20 '20 at 09:07
  • I would strongly recommend using [`nix`](https://nixos.org/nix) instead of `brew` for any kind of case where software is installing its own dependencies -- not only is the security model more effective, but Nix installs each component it builds or downloads in a separate location, so that software isn't put into the PATH for users or projects that don't need it; this also means you can have multiple incompatible versions of the same tool or library installed at the same time without conflict. – Charles Duffy Sep 20 '20 at 09:11
  • ...and even if you do stick with `brew`, safer to rewrite your command to not need `shell=True`. – Charles Duffy Sep 20 '20 at 09:14

0 Answers0