News for hackers. Stuff that matters.
Re:Fix the unit test and open a giant hole everywhere by loloquwowndueo on Saturday December 25, 2021 @07:14AM (#29682659)
So you like typing more and making your program harder to read to avoid using two apostrophes and two commas.
Re:Fix the unit test and open a giant hole everywhere by cowsandmilk on Saturday December 25, 2021 @08:37AM (#29683255)
If you have a command with lots of arguments, parent’s approach makes a lot of sense. 20 arguments that you can copy out of the shell into your program. And when you want to make changes and test via the shell, your copy and paste is also easy.

I’ve seen bugs where some forgot to add quotes and commas to split some arguments and the program did the wrong thing. Parent’s approach avoids that. However, things like spaces in quoted strings are not correctly handled.

Re:Fix the unit test and open a giant hole everywhere by loloquwowndueo on Saturday December 25, 2021 @11:15AM (#29684416)
Naively splitting commands using split() will bite you in the ass eventually. Use shlex.split as the other comment says, or just stop being lazy and craft the argument list carefully, once, and be done with it. Shortcuts here aren’t worth the risk.
Re:Fix the unit test and open a giant hole everywhere by div72 on Saturday December 25, 2021 @09:46AM (#29683712)
I am not exactly sure if parent's code execute the way you think it does. path is provided as an argument to mkdir -p, even if you set path to be a string with 20 arguments copied from your shell, it'll get passed as one.

I assume you meant something like subprocess.run(['mkdir', '-p', '--', *path.split()]), which in that case using shlex.split will fix your problems with quoted strings.