Mar-04-2023, 02:48 PM
(Mar-04-2023, 01:20 PM)DeaD_EyE Wrote: The*
in your shell is replaced with filenames, and then your shell starts the program with the arguments. You have to do this step manually.
from pathlib import Path bk_args = "-avn" # Path("somepath").glob(".*") return a Generator # the elements are Path objects # they need to be str to use them with subprocess as arguments bk_src_files = list(map(str, Path("/home/jer").glob(".*"))) bk_tar_dir = "/mnt/md0" bk_options = ['--itemize-changes=%i%f', '--info=stats2', '--progress'] print(bk_options) subprocess.run(["rsync", bk_args, *bk_options, *bk_src_dir, bk_tar_dir])
Brilliant solution DeaD_EyE! This thorn in my side finally resolved with your help!
For completeness, I wanted to provide another solution for anyone that may stumble onto this thread in the future.
The following code will also work but involves explicitly calling the shell in the subprocess.
Note: bk_src_dir = "/home/jer/.*/"
bk_str = "rsync " + bk_args + " " + bk_options + " " + bk_src_dir + " " + bk_tar_dir subprocess.run(bk_str, shell=True)I did not want to use the explicit call to the shell in the subprocess so did not implement this solution.
Thanks again!