问题描述
我在尝试将列表传递到子流程调用命令时遇到问题。我试图调用Windows robocopy函数,并传递一个应作为其过滤依据的文件类型列表。
I have a problem with trying to pass a list into a subprocess call command. I am trying to call the windows robocopy function, passing a list of file types that it should filter by.
filter_list = ['*.txt', '*.dat']
call(["robocopy", src, dst, filter_list, "/e"])
因此,传递列表本身不起作用,robocopy的输出表明它正在尝试查找文件类型 .txt .dat,就像整个列表是单个文件类型。
So passing the list itself does not work the output from robocopy showed that it was trying to find the file type ".txt.dat" as if the whole list were a single file type.
然后,我尝试了以下
call(["robocopy", src, dst, ','.join(filter_list), "/e"])
但是,这给出了与我第一次尝试相同的输出。有人知道如何传递列表并将其正确划分吗?
However that gave the same output as my first attempt. Does anyone know how to pass in a list and have it properly divided? Any help is much appriciated!
推荐答案
您实际上应该在列表中传递参数:
You should actually pass the arguments in the list:
args = ["robocopy", src, dst]
args.extend(filter_list)
args.append("/e")
call(args)
这篇关于将列表传递给子流程调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!