(no title)
theomega | 2 months ago
Basically you can just `from sh import [command]` and then have an installed binary command available as function
from sh import ifconfig
print(ifconfig("eth0"))theomega | 2 months ago
Basically you can just `from sh import [command]` and then have an installed binary command available as function
from sh import ifconfig
print(ifconfig("eth0"))
theamk|2 months ago
By default (1) captures stdout and stderr of all processes and (2) create tty for processs stdout.
Those are really bad defaults. The tty on stdout means many programs run in "interactive" rather then "batch" mode: programs which use pager get output truncated, auto-colors may get enabled and emit ESC controls into output streams (or not, depending on user's distro... fun!). And captured stderr means warnings and progress messages just disappear.
For example, this hangs forever without any output, at least if executed from interactive terminal:
Compare to "subprocess" which does the right thing and returns manpage as a string: Can you fix "sh"? sure, you need to bake in option to disable tty. But you've got to do it in _every_ script, or you'll see failure sooner or later. So it's much easier, not to mention safer, to simply use "subprocess". And as a bonus, one less dependency!(Fun fact: back when "sh" first appeared, everyone was using "git log" as an example of why tty was bad (it was silently truncating data). They fixed it.. by disabling tty only for "git" command. So my example uses "man" :) )
petters|2 months ago
Wow... yes sounds like a library to avoid!
pxc|2 months ago
https://plumbum.readthedocs.io/en/latest/local_commands.html...
It also does argument parsing and validation, so it's generally pretty useful for writing little CLI tools that invoke other CLI tools.
https://plumbum.readthedocs.io/en/latest/cli.html
Lvl999Noob|2 months ago
https://pypi.org/project/pypyp/
It takes cares of the input and output boilerplate so you can focus on the actual code that you wanted python for.
two_handfuls|2 months ago
[1] https://github.com/jean-philippe-martin/pawk
grumps|2 months ago
btown|2 months ago
https://github.com/amoffat/sh/blob/2a90b1f87a877e5e09da32fd4...
code_biologist|2 months ago
https://docs.astral.sh/uv/guides/scripts/#using-different-py...
grumps|2 months ago
zelphirkalt|2 months ago