▲ | theamk 14 days ago | |
It is that simple. You can pass arguments to `bash -c` with no problems(just don't forget a dummy $0). If you don't want exception spam, replace `check=True` with explicit exit. Here you go, it's 5 lines now.
python's shell tooling is really good (if a bit verbose). And another cool thing is "shlex.quote", so you can write something like:
and have "filename" safely inserted into script fragment.. No command escapes, and newlines, quotes, backticks etc... are all handled properly.The bash syntax highlighting will disappear, correct, and that is a downside. But hey, you are supposed to be rewriting this in python, so it's just more motivation :) |