Unless you specify shell=True
(and as a first approximation, you should never specify shell=True
), the arguments you provide are passed as is, with no shell expansions, word-splitting or dequoting. So the filename you pass as an argument is precisely /home/fricadelle/Artist - Album (2008)/*.flac
, which is not the name of any file. (That's why you don't need to add backslashes before the spaces and parentheses. If you specified shell=True
-- and I repeat, you really should avoid that -- then you would need to include backslashes so that the shell doesn't split the name into several different words.)
When you type
flac_files = "/home/fricadelle/Artist - Album (2008)/*.flac
unquoted in a shell, the shell will try to expand that to a list of all the files whose names match then pattern, and will then pass that list as separate arguments. Since subprocess.run
doesn't do this, you will have to do it yourself, which you would normally do with glob.glob
. For example,
from subprocess import run
from glob import glob
flac_files = "/home/fricadelle/Artist - Album (2008)/*.flac"
run(['metaflac', '--add-replay-gain'] + glob(flac_files))
Note: unlike the shell, glob.glob
will return an empty list if the pattern matches no files. You really should check for this error rather than invoke metaflac
with no filename options.