tomerfiliba / plumbum

Plumbum: Shell Combinators
https://plumbum.readthedocs.io
MIT License
2.8k stars 182 forks source link

Input request fails, even with & FG #321

Open timtro opened 7 years ago

timtro commented 7 years ago

Thanks in advance. I understand this is likely not a bug, but merely something I don't understand.

I am writing a script to install my working environment (on my Linux computers) and I use zsh with the oh-my-zsh suite. I would have hoped the following code works:

sh = local["bash"]
(curl[
    "-fsSL",
    "https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh"] | sh) & FG

and for the most part it does. However, the install.sh script calls chsh to change the user shell. If you run chsh, in your terminal, it will ask for the user's password. At this point, plumbum throws an exception: (Edit: I included the full stacktrace)

Time to change your default shell to zsh!
Password: chsh: PAM: Authentication failure
Traceback (most recent call last):
  File "./install-packages.py", line 144, in <module>
    main(args.PKGLST, pkmgr, pymgr)
  File "./install-packages.py", line 48, in main
    install_oh_my_zsh(pkmgr)
  File "./install-packages.py", line 91, in install_oh_my_zsh
    | sh) & FG
  File "/usr/lib/python3/dist-packages/plumbum/commands/modifiers.py", line 152, in __rand__
    timeout = self.timeout)
  File "/usr/lib/python3/dist-packages/plumbum/commands/base.py", line 90, in __call__
    return self.run(args, **kwargs)[1]
  File "/usr/lib/python3/dist-packages/plumbum/commands/base.py", line 220, in run
    return p.run()
  File "/usr/lib/python3/dist-packages/plumbum/commands/base.py", line 182, in runner
    return run_proc(p, retcode, timeout)
  File "/usr/lib/python3/dist-packages/plumbum/commands/processes.py", line 206, in run_proc
    return _check_process(proc, retcode, timeout, stdout, stderr)
  File "/usr/lib/python3/dist-packages/plumbum/commands/processes.py", line 23, in _check_process
    proc.verify(retcode, timeout, stdout, stderr)
  File "/usr/lib/python3/dist-packages/plumbum/commands/base.py", line 310, in verify
    dstproc_verify(retcode, timeout, stdout, stderr)
  File "/usr/lib/python3/dist-packages/plumbum/machines/base.py", line 22, in verify
    stdout, stderr)
plumbum.commands.processes.ProcessExecutionError: Command line: ['/bin/sh']
Exit code: 1

I can't reproduce the error if I simply do this:

>>> from plumbum import local, FG
>>> local['chsh']['-s', '/usr/bin/zsh'] & FG

so there is something about having it run inside the script, piped to bash.

Any ideas? I realise this is a shot in the dark. Feel free to close this issue if you find it inappropriate for this setting.

henryiii commented 7 years ago

It is appropriate. I will have to play with it a bit to see what is happening; I've been very pressed for time lately, but might have a a chance this weekend. I think the pipe is affecting stdin (pipe to sh).

timtro commented 7 years ago

Thanks. It isn't urgent, so don't rush for me. But I sure do appreciate your attention. I reproduced the error on my laptop, and included the full stacktrace. See the edit.