Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#722·sh

Info pushed to stdout instead of variable when invoked with contirb.sudo

Author: stephen-at-codeCreated Apr 22, 2024Updated Jun 6, 2026
Labelscant reproduce

Hi there,

I have come across a bug when I have been trying to make a call to blkid using sudo with sh. Instead of pushing the output of stdout in the sh call to a variable it instead sends the output to the user's stdout, and the variable is empty. I have attached a minimum viable test file that has shown to reproduce the issue in my environment.

Environment details: OS - Ubuntu 22.04 Kernel - 6.5.0-27-generic blkid version - 2.37.2 Python version - 3.10.12 Sh version - 2.0.6

python
import sh

def main():
    password = input("Enter password: ")
    with sh.contrib.sudo(password=password, _with=True):
        output = sh.blkid()

if __name__ == "__main__":
    main()

Source: amoffat/sh

View original on GitHubView discussion on GitHub