子进程未拾取Awscli exclude and include筛选器

2024-09-28 21:53:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这个python脚本,它可以执行,但是“参数”部分被排除在外。结果,“path”中的所有文件都被下载到“target”。理想情况下,它还应该包含“参数”部分,其中包含排除和包含过滤器。你知道吗

如何允许此脚本的“参数”部分执行?你知道吗

我也愿意在boto3等方面采取变通办法

Import awscli    
Import os
Import time   

path = 's3://source/treasure/'
target = 'C:\\Home\\Day\\'
parameter = ' --recursive --exclude "*" --include "status.2018-'
monthlog = time.strftime("%m-%d") 
execute='aws s3 cp '+path+' '+target+''+parameter+''+monthlog+'.log"'

subprocess.run(['cmd','/c',execute])

参考文献: https://docs.aws.amazon.com/cli/latest/reference/s3/index.html#use-of-exclude-and-include-filters


Tags: 文件pathimport脚本awstargetexecute参数
1条回答
网友
1楼 · 发布于 2024-09-28 21:53:33

您可以使用shell=True或将参数分解为一个列表:

execute = ['aws', 's3', 'cp', path, target, ' recursive', ' exclude', '*',  include, 'status.2018-%m-%d.log']

注意,如果不使用shell=True,则不需要在*周围加引号,因为引号仅用于抑制shell扩展;如果不使用shell,则不需要抑制它,可以直接按通配符。你知道吗

相关问题 更多 >